How to uncheck button in QButtonGroup
-
wrote on 6 Jun 2011, 12:16 last edited by
Hi all, I have QButtonGroup, at default all buttons in that group is uncheck, then user press some button, and this button become a checked - this is no problem. But then, in some function, I need to uncheck current button, I try to do like this:
@void myClass::onButtonClicked( QAbstractButton * btn){
if(btn && btn->checked())
btn->setChecked(false);@ but this cod does'nt work. Set this group not exclusive I can't because at one moment I need only one (or no one) button checked. -
wrote on 6 Jun 2011, 12:18 last edited by
What I do, as a hack, is to add one additional button to my button group, and make it invisible. I check that button through code, making the group appear to have no checked items.
If you ask me, this is an oversight in QButtonGroup that should be fixed.
-
wrote on 6 Jun 2011, 12:38 last edited by
Tnx 4 help!
-
wrote on 6 Jun 2011, 13:05 last edited by
I have one more question:
how to say button group so I need check my hidden button?
i try that, but it is'nt work :(
@....
QPushButton * nBtn = new QPushButton(this);
myBtnGroup.addButton(nBtn, 0);
...
void myClass::onButtonClicked( QAbstractButton * btn){
if(btn->isChecked()){
QAbstractButton * hidenBtn = m_myBtnGroup->button(0);
hidenBtn->setChecked(true);
return;
}
...
}@ -
wrote on 6 Jun 2011, 13:43 last edited by
This is weird... you are trying to uncheck the button in response to the signal that tells you a button just got checked? I don't think that is going to work, but the question should perhaps be why you'd want that to happen at all?
-
wrote on 6 Jun 2011, 13:56 last edited by
I need unckeck button if I(user) click to the ckecked button. That's why I try to do this like theat.
-
wrote on 4 Feb 2012, 00:05 last edited by
I had the same problem, my solution was :
// grupStatus is a pointer to QButtonGroup
@ grupStatus->setExclusive(false);
grupStatus->checkedButton()->setChecked(false);
grupStatus->setExclusive(true);
@#sorry for my English...
Marcelo. -
wrote on 2 May 2013, 22:08 last edited by
@chelock - Your english is fine.... ;-)
The setExclusive is neat.. Kinda a "obvious solution"..
But anyone filed a bug...
Would be neat to have a kinda "required" value or allowNone() or alikepete