如何仅在激活两个组合框时启用按钮

How to enable a button only when two comboboxes have been activated

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

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

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

您的代码将无法运行,因为 activated 属性是一个信号对象,其计算结果始终为 True。如果您使用 , then you need to check the 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)

也就是说,如果当前索引为零,"Select product" 消息仍会显示。