PDA

View Full Version : Does a radio button fire upon "deselection"



dennisvz
12th May 2019, 13:53
I have two radio buttons (yesRB and noRB) in a "group" such that when one is selected, the other is automatically deselected. I have separate functions tied to each button when selected.


self.ui.yesRB.toggled.connect(self.yesRB)
self.ui.noRB.toggled.connect(self.noRB)


My question: Let's say "noRB" is currently selected, and I then select "yesRB". Does the automatic "deselecting" of "noRB" trigger the function tied to "noRB" BEFORE it then triggers the function of yesRB?
thanks

anda_skoa
12th May 2019, 14:08
Yes, the toggled() signal will be emitted when the state changes either way.

You can easily detect that inside the function connected to it via the boolean parameter it carries.

Cheers,
_

dennisvz
12th May 2019, 14:45
Sorry, a follow-up question. If I have a Qcheckbox that has one function tied to it that either runs code for .isChecked(True) or code for .isChecked(False): Does checking an "unchecked" box first run the code for the False portion before running the code for True? Or, does it just run the True portion of the code?

d_stranz
12th May 2019, 16:39
Does checking an "unchecked" box first run the code for the False portion before running the code for True? Or, does it just run the True portion of the code?

This question doesn't make a lot of sense.

If you connect a slot to either the QCheckBox::stateChanged() or the QAbstractButton::toggled() signal (which QCheckBox inherits), then the signal is fired once when the state changes and the argument to the signal is the current state of the button (Qt::CheckState for a check box state change, true or false for the toggled signal).

In your slot, if you either look at the argument to the slot or at the value returned by .isChecked() method, you get the same value - true or false. There is no "isChecked( bool )" method (ie. no .isChecked(True) or .isChecked(False)). So your slot is going to decide based on the state of the check box whether to execute the code you have written to handle the case of checked or not checked.