Grabbing all QPushButton in a PyQt Python ui File

旧巷老猫 提交于 2019-12-08 05:25:18

问题


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:


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)


来源:https://stackoverflow.com/questions/13725704/grabbing-all-qpushbutton-in-a-pyqt-python-ui-file

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!