【发布时间】:2010-12-17 18:11:37
【问题描述】:
我正在为一位客户开发一个项目,该设计有一个带有专属选项的单选按钮。
这是一段代码,它运行并显示了两个漂亮的单选按钮:
self.performGroupBox = QtGui.QGroupBox(self.centralwidget)
self.performGroupBox.setGeometry(QtCore.QRect(50, 20, 181, 121))
self.performGroupBox.setObjectName("performGroupBox")
self.consultRadioButton = QtGui.QRadioButton(self.performGroupBox)
self.consultRadioButton.setGeometry(QtCore.QRect(40, 30, 84, 18))
self.consultRadioButton.setObjectName("consultRadioButton")
self.insertRadioButton = QtGui.QRadioButton(self.performGroupBox)
self.insertRadioButton.setGeometry(QtCore.QRect(40, 60, 84, 18))
self.insertRadioButton.setObjectName("insertRadioButton")
看起来像:
perform:
() Consult
() Insert
这里的重点是,如何知道标记了哪个选项:“consultRadioButton”还是“insertRadioButton”?
以下是尝试获取此信息的示例:
if self.consultRadioButton.isChecked():
self.call_Consult()
if self.insertRadioButton.isChecked():
self.call_Insert()
但在选择radiobutton被选中时它没有做任何事情。
否则,使用连接应该是另一种选择:
QtCore.QObject.connect(self.consultRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Consult)
QtCore.QObject.connect(self.insertRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Insert)
但它也不起作用。
这里缺少什么...有什么建议吗?
所有 cmets 都非常受欢迎和赞赏。
【问题讨论】:
标签: python user-interface qt qt4 pyqt