Details
-
Suggestion
-
Resolution: Unresolved
-
Not Evaluated
-
None
-
dev
Description
There are three ways to make a button exclusive in QtQuick.Controls:
1. Delegate it to autoExclusive magic
2. Use ButtonGroup on the button itself
3. Use ActionGroup on the button's action
As a side quest, it's not even specified how the latter two should interact with each other if they happened to be both managing the same button in conflicting ways! But this is not what this ticket is all about.
With so many different ways to achieve the same goal, it's hard to get things right, and even Qt's built-in Basic QQC2 style doesn't represent exclusive MenuItems very well: they are just drawn with check marks (like ChecKBox) because of checkable state, regardless of exclusivity.
In KDE's org.kde.desktop style bridge we do check for all three conditions like this:
T.MenuItem { id: controlRoot indicator: CheckIndicator { control: controlRoot } }
StylePrivate.StyleItem { // Fallback heuristic for MenuItem which can mimic either of those. elementType: (control.autoExclusive || (control.action !== null && control.action.T.ActionGroup.group !== null && control.action.T.ActionGroup.group.exclusive) || (control.T.ButtonGroup.group !== null && control.T.ButtonGroup.group.exclusive)) ? "radiobutton" : "checkbox"
It works amazingly well UI-wise, but has an unfortunate performance penalty of creating both ActionGroup and ButtonGroup attached objects per each non-autoExclusive MenuItem or any other control with CheckIndicator where elementType is not overridden.
Preferred solution
Just like many other property pairs, we could introduce a read-only "effective*" counterpart to simplify styling conditions and get rid of performance penalties: effectiveExclusive. This property would need to be re-evaluated whenever autoExclusive changes, or Button/Action groups are created or their own exclusive state changes.
It would need to be consistent with nextCheckState algorithm which I recently fixed with 488685: QQuickAbstractButton: Don't allow unchecking buttons in exclusive ActionGroups