Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Qt Python radiobutton: activate event

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

it just looks like:

perform:
    () Consult
    () Insert

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.

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) 

But it didn't work either.

What is missing here... Any suggestion?

All comments are highly welcome and appreciated.

like image 612
ThreaderSlash Avatar asked Dec 23 '22 07:12

ThreaderSlash


1 Answers

Try this signal instead:

void toggled (bool)

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

And example usage: https://www.tutorialspoint.com/pyqt/pyqt_qradiobutton_widget.htm

like image 181
Piotr Byzia Avatar answered Dec 24 '22 22:12

Piotr Byzia