0

I have a QWidget that contains a QGroupBox, which contains QComboBox, QLineEdit and QCheckBox.

I need to go around all the controls, and if the control is a QCheckBox, ask if it is checked or not. I need to know how all the QCheckBox are checked - the idea could be something like this:

count = 0
for control in groupbox.controls():
    if control is type of QtGui.QCheckBox:
        if control.isChecked:
            count = count + 1
        else:
            print('no checked')
    else:
        print('no QtGui.QCheckBox')
print ('there are '+ str(count)+ 'checked')
ekhumoro
  • 115,249
  • 20
  • 229
  • 336
GSandro_Strongs
  • 773
  • 3
  • 11
  • 24

1 Answers1

1

If the checkboxes are all children of the groupbox, then you can try this:

count = 0
for checkbox in groupbox.findChildren(QtGui.QCheckBox):
    if checkbox.isChecked():
        count += 1
print('there are %s checked' % count)

The checkboxes will be children of the groupbox if they were created like this:

checkbox = QtGui.QCheckBox('Title', groupbox)
ekhumoro
  • 115,249
  • 20
  • 229
  • 336