Reputation: 39
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)
Upvotes: 1
Views: 232
Reputation: 120818
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.
Upvotes: 1