1

I have two combo boxes, and this is my attempt to enable a button only when options in both boxes are selected.

However, when I select only one comboBox, the button will enable itself.

    if self.page2.comboBox2.activated and self.page2.comboBox.activated:
        self.page2.viewbutton.setEnabled(True)
    else:
        self.page2.viewbutton.setEnabled(False)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
hope
  • 39
  • 4
  • use `print()` to see what you have in variables and what you get for `self.page2.comboBox2.activated and self.page2.comboBox.activated` – furas Nov 07 '19 at 08:06

1 Answers1

1

Your code won't work, because the activated attribute is a signal object, which will always evaluate to True. If you are using comboboxes like the ones in your other question, then you need to check the current index to see whether the user has selected a valid option:

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

That is, if the current index is zero, the "Select product" message is still shown.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
ekhumoro
  • 115,249
  • 20
  • 229
  • 336