Not understand the class of QRadioButton very well!
is the radiobutton checked false after the code
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?
Re: Not understand the class of QRadioButton very well!
Quote:
is the radiobutton checked false after the code
YES.
Quote:
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:
Quote:
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
Re: Not understand the class of QRadioButton very well!
Quote:
Originally Posted by
BalaQT
YES.
NO.
Quote:
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.
Re: Not understand the class of QRadioButton very well!
is the radiobutton checked false after the code
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.
Re: Not understand the class of QRadioButton very well!
Please show more code and not just one line.
Why don't you write some debug output to verify your assumtions:
Code:
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();
Re: Not understand the class of QRadioButton very well!
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.
Re: Not understand the class of QRadioButton very well!
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.