繁体   English   中英

Qt Python radiobutton:激活事件

[英]Qt Python radiobutton: activate event

我正在为一个客户开发一个项目,其中设计有一个带有独家选项的单选按钮。

这是一段代码,它运行并显示两个漂亮的单选按钮:

    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()

但是当选择无线电按钮时它没有做任何事情。

否则,使用connect应该是另一种选择:

    QtCore.QObject.connect(self.consultRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Consult)  
    QtCore.QObject.connect(self.insertRadioButton, QtCore.SIGNAL("currentIndexChanged(QString)"), self.call_Insert) 

但它也没有用。

这里缺少什么...有什么建议吗?

所有评论都非常欢迎和赞赏。

这是解决方案...现在正在工作:

QtCore.QObject.connect(self.radioButton1,QtCore.SIGNAL("toggled(bool)"),self.radio_activateInput)

当包含参数bool切换到信号时,它工作。

# Assuming 'self' is a QtGui object
self.consultRadioButton = QtGui.QRadioButton('Consult')
# I prefer layout managers, but that is another topic
self.consultRadioButton.setGeometry(QtCore.QRect(40, 30, 84, 18))
self.consultRadioButton.setObjectName("consultRadioButton")

self.insertRadioButton = QtGui.QRadioButton('Insert')
self.insertRadioButton.setGeometry(QtCore.QRect(40, 60, 84, 18))
self.insertRadioButton.setObjectName("insertRadioButton")

# Set Default
self.consultRadioButton.setChecked(True)

# Create a Group and make it exclusive
self.methodGrp.setExclusive(True)

# Add radio buttons to group
self.methodGrp.addButton(self.consultRadioButton)
self.methodGrp.addButton(self.insertRadioButton)

# Connect Event handlers
self.consultRadioButton.clicked.connect(self.callConsult)
self.insertRadioButton.clicked.connect(self.callInsert)

看看QButtonGroup类

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM