簡體   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