Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to uncheck button in QButtonGroup
QtWS25 Last Chance

How to uncheck button in QButtonGroup

Scheduled Pinned Locked Moved General and Desktop
8 Posts 4 Posters 16.5k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • M Offline
    M Offline
    maxim.prishchepa
    wrote on 6 Jun 2011, 12:16 last edited by
    #1

    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.

    Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

    1 Reply Last reply
    0
    • A Offline
      A Offline
      andre
      wrote on 6 Jun 2011, 12:18 last edited by
      #2

      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.

      1 Reply Last reply
      2
      • M Offline
        M Offline
        maxim.prishchepa
        wrote on 6 Jun 2011, 12:38 last edited by
        #3

        Tnx 4 help!

        Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

        1 Reply Last reply
        0
        • M Offline
          M Offline
          maxim.prishchepa
          wrote on 6 Jun 2011, 13:05 last edited by
          #4

          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;
          }
          ...
          }@

          Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

          1 Reply Last reply
          0
          • A Offline
            A Offline
            andre
            wrote on 6 Jun 2011, 13:43 last edited by
            #5

            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?

            1 Reply Last reply
            0
            • M Offline
              M Offline
              maxim.prishchepa
              wrote on 6 Jun 2011, 13:56 last edited by
              #6

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

              Programming Is Like Sex: One mistake and you have to support it for the rest of your life. (Michael Sinz).

              1 Reply Last reply
              0
              • C Offline
                C Offline
                chelock
                wrote on 4 Feb 2012, 00:05 last edited by
                #7

                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.

                1 Reply Last reply
                1
                • P Offline
                  P Offline
                  pedromorgan
                  wrote on 2 May 2013, 22:08 last edited by
                  #8

                  @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

                  pete

                  1 Reply Last reply
                  0

                  • Login

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • Users
                  • Groups
                  • Search
                  • Get Qt Extensions
                  • Unsolved