tags:

views:

396

answers:

4

Hi Everybody,

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.

+3  A: 

Try this signal instead:

void toggled (bool)

http://www.riverbankcomputing.co.uk/static/Docs/PyQt4/html/qabstractbutton.html#toggled

piobyz
A: 

Thanks for your suggestion. I also looked in the QGroupBox Class Reference - http://doc.trolltech.com/4.3/qgroupbox.html but it didn't provide any useful explanation on how to connect signal/slot for radiobutton.

Here is what was added to the code:

    self.radioButton1.setCheckable(True)
    self.radioButton1.setChecked(True)
    self.radioButton2.setCheckable(True)

Then called to connect events:

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

and also tried:

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

But it is not working yet.

Any other suggestion? All comments are highly appreciated.

ThreaderSlash
On StackOverflow, don't put comments/responses in as "Answers". Edit your question or click "Add comment" below other people's answers.
Craig McQueen
A: 

Here is solution... now working:

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

when have the parameter bool included into toggled to signal, it worked.

ThreaderSlash
A: 

Take a look at QButtonGroup class

Kamil Klimek