PDA

View Full Version : Not understand the class of QRadioButton very well!



wter27
24th January 2011, 12:32
is the radiobutton checked false after the code

ui->radioButton_2->setChecked(false);
every time i use the code above ,but the radiobutton could not being checked false after i clicked one radiobutton.I just don't know why the radiobutton could not be checked false again?Did I use the wrong class?

BalaQT
24th January 2011, 12:55
is the radiobutton checked false after the code
YES.


why the radiobutton could not be checked false again?Did I use the wrong class?
u r using the right class only. from where u r calling this code?

check the doc:

Radio buttons are autoExclusive by default. If auto-exclusive is enabled, radio buttons that belong to the same parent widget behave as if they were part of the same exclusive button group. If you need multiple exclusive button groups for radio buttons that belong to the same parent widget, put them into a QButtonGroup.

Bala

wysota
24th January 2011, 13:09
YES.
NO.


u r using the right class only. from where u r calling this code?
No, it's not the right class. If you want to be able to uncheck a button, use QCheckBox and not QRadioButton. You can make them non-exclusive but this effectively makes the button a check box.

wter27
24th January 2011, 14:49
is the radiobutton checked false after the code

ui->radioButton_2->setChecked(false);
every time i use the code above ,but the radiobutton could not being checked false after i clicked one radiobutton.I just don't know why the radiobutton could not be checked false again?Did I use the wrong class?

I know the QButtonGroup and I enable the autoExclusive so that there is only one radiobutton could be checked true in the group.But I am wondering maybe I call this code in the wrong place.I use the QScrollBar ' signal valueChanged(int) to the ui->radiobutton->setChecked(false),once the value of the QScrollBar is changed ,the executive will call the code ui->radiobutton->setChecked(false).I was just thinking like this.Maybe I'm wrong.By the way ,is it the right way to use the QScrollBar ' signal valueChanged(int) what I just mentioned or not.Please give me some tips. My mother language is not english .So it is hard for me to read the doc.

nightghost
24th January 2011, 16:45
Please show more code and not just one line.

Why don't you write some debug output to verify your assumtions:



qDebug() << "[BEFORE]: Radio button is checked:" << ui->radioButton_2->isChecked();
ui->radioButton_2->setChecked(false);
qDebug() << "[AFTER]: Radio button is checked:" << ui->radioButton_2->isChecked();

wysota
24th January 2011, 16:49
In general calling setChecked(false) on a radio button does nothing (unless you explicitly disable exclusivity). You need to call setChecked(true) on some other button to cause this button to be unchecked.

maxpaayne
24th January 2011, 21:57
QRadioButton class is a radio button, which can be switched checked or unchecked. Typically, the radio buttons to show the user "one of many" choice. Group of radio buttons only one button at a time can be controlled if the user selects another button, the button selected above is turned off.