我在 Qt Designer 中制作了一个 GUI,我有 144 个复选框。我想用 QPushButton 将它们全部连接起来以选中和取消选中所有这些。
我怎样才能做到这一点?它们都在 QGridLayout 中。
他们是按照“趋势”命名的,所以我试着把他们的名字写在一个列表中,并调用列表中的每个项目来检查,但我没有做到。
这个例子或多或少像我所拥有的
# -*- coding: utf-8 -*-
# Form implementation generated from reading ui file 'check.ui'
#
# Created by: PyQt4 UI code generator 4.11.4
#
# WARNING! All changes made in this file will be lost!
from PyQt4 import QtCore, QtGui
try:
_fromUtf8 = QtCore.QString.fromUtf8
except AttributeError:
def _fromUtf8(s):
return s
try:
_encoding = QtGui.QApplication.UnicodeUTF8
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig, _encoding)
except AttributeError:
def _translate(context, text, disambig):
return QtGui.QApplication.translate(context, text, disambig)
class Ui_Form(object):
def setupUi(self, Form):
Form.setObjectName(_fromUtf8("Form"))
Form.resize(400, 300)
self.gridLayout = QtGui.QGridLayout(Form)
self.gridLayout.setObjectName(_fromUtf8("gridLayout"))
self.checkBox_2 = QtGui.QCheckBox(Form)
self.checkBox_2.setObjectName(_fromUtf8("checkBox_2"))
self.gridLayout.addWidget(self.checkBox_2, 2, 0, 1, 2)
self.checkBox = QtGui.QCheckBox(Form)
self.checkBox.setObjectName(_fromUtf8("checkBox"))
self.gridLayout.addWidget(self.checkBox, 2, 2, 1, 1)
self.checkBox_3 = QtGui.QCheckBox(Form)
self.checkBox_3.setObjectName(_fromUtf8("checkBox_3"))
self.gridLayout.addWidget(self.checkBox_3, 3, 0, 1, 2)
self.checkBox_4 = QtGui.QCheckBox(Form)
self.checkBox_4.setObjectName(_fromUtf8("checkBox_4"))
self.gridLayout.addWidget(self.checkBox_4, 3, 2, 1, 1)
self.checkBox_5 = QtGui.QCheckBox(Form)
self.checkBox_5.setObjectName(_fromUtf8("checkBox_5"))
self.gridLayout.addWidget(self.checkBox_5, 1, 2, 1, 1)
self.checkBox_6 = QtGui.QCheckBox(Form)
self.checkBox_6.setObjectName(_fromUtf8("checkBox_6"))
self.gridLayout.addWidget(self.checkBox_6, 1, 0, 1, 1)
self.retranslateUi(Form)
QtCore.QMetaObject.connectSlotsByName(Form)
def retranslateUi(self, Form):
Form.setWindowTitle(_translate("Form", "Form", None))
self.checkBox_2.setText(_translate("Form", "CheckBox", None))
self.checkBox.setText(_translate("Form", "CheckBox", None))
self.checkBox_3.setText(_translate("Form", "CheckBox", None))
self.checkBox_4.setText(_translate("Form", "CheckBox", None))
self.checkBox_5.setText(_translate("Form", "CheckBox", None))
self.checkBox_6.setText(_translate("Form", "CheckBox", None))
if __name__ == "__main__":
import sys
app = QtGui.QApplication(sys.argv)
Form = QtGui.QWidget()
ui = Ui_Form()
ui.setupUi(Form)
Form.show()
sys.exit(app.exec_())
我想制作一个按钮来检查和取消选中所有这些,而不必键入 ao the connect
s