Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-115000

Feature request: Add AbstractButton::effectiveExclusive property

    XMLWordPrintable

Details

    • Suggestion
    • Resolution: Unresolved
    • Not Evaluated
    • None
    • dev
    • Quick: Controls 2
    • All

    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:

      https://invent.kde.org/frameworks/qqc2-desktop-style/-/blob/335f79e3d86257fed7ed8da29a592aa0677cbc0a/org.kde.desktop/MenuItem.qml#L104

      MenuItem.qml
      T.MenuItem {
          id: controlRoot
          indicator: CheckIndicator {
              control: controlRoot
          }
      }
      

      https://invent.kde.org/frameworks/qqc2-desktop-style/-/blob/335f79e3d86257fed7ed8da29a592aa0677cbc0a/org.kde.desktop/CheckIndicator.qml#L21-24

      CheckIndicator.qml
      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

      Attachments

        No reviews matched the request. Check your Options in the drop-down menu of this sections header.

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            ratijas ivan tkachenko
            Votes:
            0 Vote for this issue
            Watchers:
            1 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There are no open Gerrit changes