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. QRadioButton and QGroupBox
QtWS25 Last Chance

QRadioButton and QGroupBox

Scheduled Pinned Locked Moved Unsolved General and Desktop
6 Posts 3 Posters 1.7k 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.
  • S Offline
    S Offline
    SPlatten
    wrote on 9 Nov 2021, 14:16 last edited by
    #1

    I was previously using a QButtonGroup and when using this the group function of the radio button does return the group, however this isn't the case when using QGroupBox. I understand from searching online that QGroupBox replaces QButtonGroup. Am I wrong...again?

    Kind Regards,
    Sy

    J 1 Reply Last reply 9 Nov 2021, 14:35
    0
    • S SPlatten
      9 Nov 2021, 14:16

      I was previously using a QButtonGroup and when using this the group function of the radio button does return the group, however this isn't the case when using QGroupBox. I understand from searching online that QGroupBox replaces QButtonGroup. Am I wrong...again?

      J Offline
      J Offline
      JonB
      wrote on 9 Nov 2021, 14:35 last edited by JonB 11 Sept 2021, 14:44
      #2

      @SPlatten
      QGroupBox does not require QButtonGroup.

      QGroupBox is a visual element. You can visit all widgets inside it if you wish.

      QButtonGroup is a logical element. It does not render anything to the screen. It is used purely to group and access a bunch of widgets in a logical fashion. It only accepts radiobuttons/checkboxes, and is principally convenient for dealing with them where you only want one element in the group to be checked.

      [I forgot to say: If it suits your coding, there is nothing to stop you having a QGroupBox (for visuals) and a QButtonGroup (for logical handling) if you wish. The latter makes it easier to address the child elements than in the former, though you can manage without it and deal with the group box's children instead.]

      S 1 Reply Last reply 9 Nov 2021, 14:37
      4
      • J Offline
        J Offline
        JoeCFD
        wrote on 9 Nov 2021, 14:37 last edited by
        #3

        Think about you have more than one set of radio buttons in one group box. What will happen?

        S 1 Reply Last reply 9 Nov 2021, 14:38
        0
        • J JonB
          9 Nov 2021, 14:35

          @SPlatten
          QGroupBox does not require QButtonGroup.

          QGroupBox is a visual element. You can visit all widgets inside it if you wish.

          QButtonGroup is a logical element. It does not render anything to the screen. It is used purely to group and access a bunch of widgets in a logical fashion. It only accepts radiobuttons/checkboxes, and is principally convenient for dealing with them where you only want one element in the group to be checked.

          [I forgot to say: If it suits your coding, there is nothing to stop you having a QGroupBox (for visuals) and a QButtonGroup (for logical handling) if you wish. The latter makes it easier to address the child elements than in the former, though you can manage without it and deal with the group box's children instead.]

          S Offline
          S Offline
          SPlatten
          wrote on 9 Nov 2021, 14:37 last edited by
          #4

          @JonB, thank you

          Kind Regards,
          Sy

          1 Reply Last reply
          0
          • J JoeCFD
            9 Nov 2021, 14:37

            Think about you have more than one set of radio buttons in one group box. What will happen?

            S Offline
            S Offline
            SPlatten
            wrote on 9 Nov 2021, 14:38 last edited by
            #5

            @JoeCFD The behaviour is the same, adding the radio buttons with the same parent forms the group. I have 5 radio buttons in each group, only one can be selected, each group can have a different selection.

            Kind Regards,
            Sy

            J 1 Reply Last reply 9 Nov 2021, 14:43
            0
            • S SPlatten
              9 Nov 2021, 14:38

              @JoeCFD The behaviour is the same, adding the radio buttons with the same parent forms the group. I have 5 radio buttons in each group, only one can be selected, each group can have a different selection.

              J Offline
              J Offline
              JoeCFD
              wrote on 9 Nov 2021, 14:43 last edited by JoeCFD 11 Sept 2021, 14:45
              #6

              @SPlatten For example: you lay out 5 radio buttons in a group box: 3 are mutually exclusive and the other two are the same. In this case, you need two qbuttongroups for the three and two radio buttons. If all five are mutually exclusive, qbuttongroup is not needed.

              The buttons in a button group are usually checkable QPushButtons, QCheckBoxes (normally for non-exclusive button groups), or QRadioButtons.
              https://doc.qt.io/qt-5/qbuttongroup.html#details

              1 Reply Last reply
              2

              5/6

              9 Nov 2021, 14:38

              • Login

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