Qt Python单选按钮:激活事件 [英] Qt Python radiobutton: activate event

查看:155
本文介绍了Qt Python单选按钮:激活事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

I am developing a project for one customer, where the design has a radio button with exclusive options.

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

Here is a piece of the code that runs and show two nice radio buttons:

    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"?

The point here is, how to know what choice was marked: "consultRadioButton" or "insertRadioButton"?

以下是尝试获取此信息的示例:

Here is a sample on trying to get this information:

    if self.consultRadioButton.isChecked():
        self.call_Consult()
    if self.insertRadioButton.isChecked():
        self.call_Insert()

But it didn't do anything when the radiobutton is chosen.

But it didn't do anything when the radiobutton is chosen.

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

Otherwise, using connect should be another option:

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

但也没有用.

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

What is missing here... Any suggestion?

非常欢迎和感谢所有评论.

All comments are highly welcome and appreciated.

推荐答案

试试这个信号:

void toggled (bool)

https://doc.qt.io/qt-5/qabstractbutton.html#toggle

和示例用法:https://www.tutorialspoint.com/pyqt/pyqt_qradiobutton_widget.htm

这篇关于Qt Python单选按钮:激活事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆