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. QButtonGroup in QBoxLayout
Forum Updated to NodeBB v4.3 + New Features

QButtonGroup in QBoxLayout

Scheduled Pinned Locked Moved General and Desktop
12 Posts 3 Posters 12.6k Views 1 Watching
  • 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.
  • B Offline
    B Offline
    blackbelt
    wrote on last edited by
    #3

    thanky. If you have three RadioButton how do you chck wich one is currently checked?

    1 Reply Last reply
    0
    • L Offline
      L Offline
      leon.anavi
      wrote on last edited by
      #4

      [quote author="blackbelt" date="1342710428"]thanky. If you have three RadioButton how do you chck wich one is currently checked?[/quote]

      Just follow the documentation :)

      bq. Use "isChecked()":http://qt-project.org/doc/qt-4.8/qabstractbutton.html#checked-prop to see if a particular button is selected.

      http://anavi.org/

      1 Reply Last reply
      0
      • B Offline
        B Offline
        blackbelt
        wrote on last edited by
        #5

        yes of course. But I have to check every RadioButton. The QButtonGroup has a signal that takes as formal paramter QAbstractButton (the button you clicked)

        1 Reply Last reply
        0
        • L Offline
          L Offline
          leon.anavi
          wrote on last edited by
          #6

          Declare a slot that is called when one of buttons in QButtonGroup is clicked.

          @
          public slots:

          void buttonClicked(QAbstractButton* button);
          @

          Bind the signal and the slot

          @
          connect(this , SIGNAL(buttonClicked(QAbstractButton*)),this,SLOT(buttonClick(QAbstractButton*)));
          @

          Detect the button based on it's text.

          @
          void MyClass::buttonClicked(QAbstractButton* button);
          {
          if ("radio button text" == button->text())
          {
          // * * *
          }
          }
          @

          http://anavi.org/

          1 Reply Last reply
          0
          • B Offline
            B Offline
            blackbelt
            wrote on last edited by
            #7

            what is "this"? Every RadioButto?

            1 Reply Last reply
            0
            • A Offline
              A Offline
              andre
              wrote on last edited by
              #8

              I'd go for the [[doc:QButtonGroup]] solution.
              You can add the buttons to a group from within designer.

              Simply add the radio buttons to your form. Select them all, and right click on any of them. Choose Add to Buttongroup -> New buttongroup. Nothing obvious will change, but in your Object Inspector pane you'll notice a new QButtonGroup object. Select it to change the name to something sensible.

              Now, you can simply connect to the button groups' signals. If you need more control of the ID's of each of the group member, you'll need to do the construction of the button group and the adding of the radio buttons in code. I'd do that once in your constructor. After that, you can use its signals again.

              -Note that a QGroupBox also works as a QButtonGroup.-

              1 Reply Last reply
              0
              • B Offline
                B Offline
                blackbelt
                wrote on last edited by
                #9

                so QGroupBox would receive the same buttonClicked(QAbstractButton*) signal of QGroupButton?

                Thank you

                1 Reply Last reply
                0
                • A Offline
                  A Offline
                  andre
                  wrote on last edited by
                  #10

                  Actually, I was wrong on QGroupBox. Though it will make QRadioButton's behave exclusively between the ones inside the group box, it does not provide the signalling QButtonGroup provides. My apologies.

                  1 Reply Last reply
                  0
                  • B Offline
                    B Offline
                    blackbelt
                    wrote on last edited by
                    #11

                    Nerver mind. So cominng back to the original question:

                    Is it possible to a QButtonGroup in a QBoxLayout? If yes, how?

                    Thank you

                    1 Reply Last reply
                    0
                    • A Offline
                      A Offline
                      andre
                      wrote on last edited by
                      #12

                      No, because QButtonGroup is not a widget. However, you can add the radio buttons to the box layout, and still add those radio buttons to a QButtonGroup.

                      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