setchecked( true) of the radio button doesn't work
Hello,
In the UI of my application, there are several radio buttons. They work well when I click them.
However, when I use raidoButton_1->setChecked(true) to set them, UI doesn't change. Shall I call some other functions to update them?
Thank you!
Re: setchecked( true) of the radio button doesn't work
Quote:
Originally Posted by
richardander
However, when I use raidoButton_1->setChecked(true) to set them, UI doesn't change. Shall I call some other functions to update them?
No, there is no need. It should work unless you block the event loop somehow. Do you have a busy loop in your application?
Re: setchecked( true) of the radio button doesn't work
There is no busy loop in the application.
Could you let me know what are the commands/functions in QT that can block the event loop?
Thank you!
Re: setchecked( true) of the radio button doesn't work
Does this work for you?
Code:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
button1.setChecked(true);
button2.setChecked(false);
button1.show();
button2.show();
return app.exec();
}
Are you sure that the code where you change the check state gets actually executed?
Re: setchecked( true) of the radio button doesn't work
Hello,
The code works. In fact, I did another test: put three radio buttons in one qgroupbox. Using setChecked( true) to select one radio button. But, if I want to clear the selection, the setChecked( false ) seems not working. In following code, first radio button is selected. But it can not be unselected.
Code:
// main.cpp
#include <QtGui>
int main(int argc, char* argv[])
{
vbox->addWidget(radio1);
vbox->addWidget(radio2);
vbox->addWidget(radio3);
vbox->addStretch(1);
groupBox->setLayout(vbox);
groupBox->show();
radio1->setChecked(true);
radio1->setChecked(false);
return app.exec();
}
Is there any way to make no radiobutton selected?
Thank you!
Re: setchecked( true) of the radio button doesn't work
put needed radiobutons in QGroupBox.
Re: setchecked( true) of the radio button doesn't work
As shown in the above sample code, the three radio buttons have been put in the QGroupBox so that only one radiobutton can be selected.
however, if I want to clear the current selection and make all radiobutton unselected, what shall I do?
thank you!
Re: setchecked( true) of the radio button doesn't work
try to add the following code to yours
Code:
...
radio1->setCheckable(false);
radio2->setCheckable(false);
radio3->setCheckable(false);
...
but in this case you can't be able to check buttons at all.
Re: setchecked( true) of the radio button doesn't work
Radio buttons are "auto-exclusive" 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.
Re: setchecked( true) of the radio button doesn't work