如何获取PyQt中QGroupbox中存在的Qcheckbox的状态
发布时间:2020-12-20 11:34:12 所属栏目:Python 来源:网络整理
导读:我的项目包含Qdialog有多个QGroupbox.Each GroupBox包含一些复选框.所有groupbox的复选框列表都相同.我没有太多的声誉来加载图像:( 在这里,用户可以根据需要选择复选框,然后按下确定按钮.按下确定按钮后,我应该能够获得用户选中的复选框列表. 我在循环中创建
我的项目包含Qdialog有多个QGroupbox.Each GroupBox包含一些复选框.所有groupbox的复选框列表都相同.我没有太多的声誉来加载图像:(
在这里,用户可以根据需要选择复选框,然后按下确定按钮.按下确定按钮后,我应该能够获得用户选中的复选框列表. 我在循环中创建复选框,这是代码: def createGroupBox(self,livename,shotlist): groupBox = QtGui.QGroupBox("Live-"+livename) grpLayout = QtGui.QVBoxLayout() i=0 while i != (len(shotlist)-2): qChkBx_shot = QtGui.QCheckBox("Shot-"+shotlist[i],self) qChkBx_shot.stateChanged.connect(lambda: self.groupcheckBoxToggled(livename,qChkBx_shot.text())) grpLayout.addWidget(qChkBx_shot,QtCore.Qt.AlignCenter) i +=1 groupBox.setLayout(grpLayout) return groupBox 使用以下代码的GroupBox: def InitUi(self,livelist,shotlist): scrolllayout = QtGui.QGridLayout() scrollwidget = QtGui.QWidget() scrollwidget.setLayout(scrolllayout) scroll = QtGui.QScrollArea() scroll.setWidgetResizable(True) # Set to make the inner widget resize with scroll area scroll.setWidget(scrollwidget) i=0 length = len(livelist)-2 x,y=0,0 while x <= math.ceil(length/4): for y in range(0,4): if (i < (length)): groupbox=self.createGroupBox(livelist[i],shotlist) self.groupboxes.append(groupbox) scrolllayout.addWidget(groupbox,x,y) y +=1 i +=1 x+=1 self.Okbutton = QtGui.QPushButton('OK',self) self.Okbutton.clicked.connect(lambda: self.buttonPressed()) self.Okbutton.setMaximumWidth(100) layout = QtGui.QVBoxLayout() layout.addWidget(scroll) layout.addWidget(self.Okbutton,QtCore.Qt.AlignRight) self.setLayout(layout) self.setWindowTitle("Customized LiveShotLiveSwitching") self.resize(1200,500) self.show() 在这里,我的查询是,我能够检索哪个组框被激活的值,我无法获得在该组框下检查的复选框列表. 任何人都可以帮我解决这个问题…… 解决方法
使groupbox成为每个复选框的父级:
qChkBx_shot = QtGui.QCheckBox("Shot-"+shotlist[i],groupBox) 现在,您可以使用以下内容遍历组框的复选框: for checkbox in groupbox.findChildren(QtGui.QCheckBox): print('%s: %s' % (checkbox.text(),checkbox.isChecked())) 要获取组合框,该复选框属于: groupbox = checkbox.parent() (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |