【问题标题】:How to enable a button only when two comboboxes have been activated如何仅在激活两个组合框时启用按钮
【发布时间】:2020-03-03 18:11:13
【问题描述】:

我有两个组合框,这是我尝试仅在选择两个框中的选项时启用按钮。

但是,当我只选择一个组合框时,按钮会自动启用。

    if self.page2.comboBox2.activated and self.page2.comboBox.activated:
        self.page2.viewbutton.setEnabled(True)
    else:
        self.page2.viewbutton.setEnabled(False)

【问题讨论】:

  • 使用print()查看变量中的内容以及self.page2.comboBox2.activated and self.page2.comboBox.activated获得的内容

标签: python pyqt pyqt5 qcombobox


【解决方案1】:

您的代码将无法工作,因为activated 属性是一个信号对象,它的计算结果始终为True。如果您使用的是 your other question 中的组合框,则需要检查 current index 以查看用户是否选择了有效选项:

if (self.page2.comboBox2.currentIndex() > 0 and
    self.page2.comboBox.currentIndex() > 0):
    self.page2.viewbutton.setEnabled(True)
else:
    self.page2.viewbutton.setEnabled(False)

也就是说,如果当前索引为零,仍然会显示“选择产品”消息。

【讨论】:

    猜你喜欢
    • 2015-03-01
    • 2020-02-28
    • 1970-01-01
    • 2015-06-03
    • 1970-01-01
    • 2014-01-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多