在以下示例上订立,我如何传递/访问更多属性,然后再访问qCheckbox的'状态'?在这种情况下
类似的东西(我主要是在" iLcheckbox_changed"定义中使用"态度"的" objectName"的正确名称,也许更一般而言我如何找到可以通过的其他属性)<)
import sys
from PyQt4.QtGui import *
from PyQt4.QtCore import *
class SelectionWindow(QMainWindow):
def __init__(self, parent=None):
super(SelectionWindow, self).__init__()
self.ILCheck = False
ILCheckbox = QCheckBox(self)
ILCheckbox.setCheckState(Qt.Unchecked)
self.check_box_dict = {}
ILCheckbox.stateChanged.connect(self.ILCheckbox_changed)
MainLayout = QGridLayout()
MainLayout.addWidget(ILCheckbox, 0, 0, 1, 1)
self.setLayout(MainLayout)
def ILCheckbox_changed(self, state, objectName):
self.ILCheck = (state == Qt.Checked)
print(self.ILCheck)
self.check_box_dict[objectName] = self.ILCheck
if __name__ == '__main__':
app = QApplication(sys.argv)
window = SelectionWindow()
window.show()
sys.exit(app.exec_())
在每个插槽中,您都可以访问带有函数self.sender()
def ILCheckbox_changed(self, state):
self.ILCheck = (state == Qt.Checked)
print(self.ILCheck)
self.check_box_dict[self.sender()] = self.ILCheck
print(self.check_box_dict)