QRadioButton and QGroupBox
-
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?
-
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?
@SPlatten
QGroupBox
does not requireQButtonGroup
.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 aQButtonGroup
(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.] -
@SPlatten
QGroupBox
does not requireQButtonGroup
.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 aQButtonGroup
(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.] -
Think about you have more than one set of radio buttons in one group box. What will happen?
-
@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.
@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