Reputation: 199
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?
Upvotes: 2
Views: 1457
Reputation: 120568
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)
Upvotes: 5