How to uncheck button in QButtonGroup

  • 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.

  • 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.

  • Tnx 4 help!

  • 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){
    QAbstractButton * hidenBtn = m_myBtnGroup->button(0);

  • 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?

  • I need unckeck button if I(user) click to the ckecked button. That's why I try to do this like theat.

  • I had the same problem, my solution was :

    // grupStatus is a pointer to QButtonGroup

    @ grupStatus->setExclusive(false);



    #sorry for my English...

  • @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 alike


Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.