Important: Please read the Qt Code of Conduct -

Imitate QRadioButton for QGroupBox

  • Hello

    I try to create a customized QGroupBox which contains QWidget elements. These elements aren't QRadioButtons but have a similar behaviour, they are checkable and so on but also have additional sub-elements inside them. Is it possible to configure these QWidget elements in a way, that the QGroupBox sees them as QRadioButtons, so that exclusive selection is enabled?

    Thanks for any help!

  • You could use the press slot of your elements to disable the others in the group. So if one is checked, the others switch to unchecked

  • Lifetime Qt Champion


    I think the elements must be inherited from QAbstractButton for this to work.

  • Or from checkbox, or graphicssceneitem if it's something on the graphicsview. It depends on the element

  • Lifetime Qt Champion

    Checkbox is a QAbstractButton child.
    I think QButtonGroup is the one doing the real work of "exclusive" so I wonder if its possible to
    create a child of QButtonGroup and teach it to handle new types.
    But for QGroupBox, I did not trip over anything that suggest it can use another QButtonGroup. :(

Log in to reply