Question

Is it possible to disable a check box from the moment a UI is run?

I have two steps in my UI. I would like the check boxes of step 2 to remained unchecked until a box in step one is selected.

Is this possible? I can't figure out how to do it with signal/slot.

In the image below I would like Step 2 to be disabled until a box in step 2 is clicked.

enter image description here

Était-ce utile?

La solution

To disable checkboxes by default in Qt Designer, set the enabled property accordingly (it's at the top of the QWidget section).

For managing the state of the checkboxes, I would suggest adding each set of checkboxes to a QButtonGroup (this would probably be done in the __init__ for your main-window class):

    self.group1 = QtGui.QButtonGroup(self)
    self.group1.setExclusive(False)
    self.group1.addButton(self.checkboxA)
    self.group1.addButton(self.checkboxB)
    self.group1.addButton(self.checkboxC)
    self.group1.buttonClicked.connect(self.handleStepOneButtons)

    # self.group2 = QtGui.QButtonGroup(self)
    # ...
    # self.group2.buttonClicked.connect(self.handleStepTwoButtons)

And then the handler for the Step 1 checkboxes can control the state of the Step 2 checkboxes like this:

def handleStepOneButtons(self, button):
    checked = (self.group1.checkedButton() is not None)
    for checkbox in self.group2.buttons():
        checkbox.setEnabled(checked)
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top