python使用pyqt获取按钮文本,在PyQt Python ui文件中抓取所有QPushButton

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?

解决方案

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)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值