2

I created a UI File using Qt Designer with lots of QPushButtons, and then I converted it into a python file using pyuic4.

I want to add all the QPushButtons to a QButtonGroup.

How do I iterate or grab all my QPushButtons to add in to a QButtonGroup from my UI Python file?

1 Answer 1

5

In Qt Designer, put all your buttons inside a container widget.

You can then use findChildren to iterate over all the child buttons. So if self.buttonBox was your container widget, then you could do something like:

self.buttonGroup = QtGui.QButtonGroup(self)
for button in self.buttonBox.findChildren(QtGui.QAbstractButton):
    self.buttonGroup.addButton(button)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.