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

Forced 'checkable' property of ItemDelegate interferes with editable models

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P2: Important P2: Important
    • 6.2.0 Alpha
    • 5.6, 6.1.0
    • Quick: Controls 2
    • None
    • All
    • 4f73c07b529d2437e72bfdf4c1a75f83e2bdbe76 (qt/qtquickcontrols2/dev)

      On `AbstractButton::checked` property set to true, the button property AbstractButton::checkable is forced to `true` too.

      This behavior was introduced to simplify buttons setup:

          Button { checked: true }

          Button { checkable: true }

      (the first button is forced to be checkable)

      ItemDelegate inherits this behavior but unfortunately, 'checkable' delegates are not fully compatible with models: The model API provides a means to reject the data change (QAIM::setData() can return 'false' ). In that case, a checkable delegate state will get out of sync, because the delegate changes its state on the user action.
      To make the delegate correctly work with non-trivial models, the delegate should be kept uncheckable. On the Qt side, there is a code that forces the Delegate to be checkable on the (binded) model data changed to true.

      The following unidirectional data flow should take its place:

      1. The delegate state always represents the model data.
      2. On the user action, the delegate requests the model to adjust the data.
      3. The model validates and performs the request.
      4. The model notifies the views about the data changes via the standard Qt API (dataChanged signal).
      5. The delegate updates its state on dataChanged() signal received.

      The "Setting checked to true forces checkable property to true" behavior added to save one property setup in trivial cases, results in the need to revert the forced "checkable" property changes in model-driven AbstractButton instances (such as CheckDelegate, SwitchDelegate and customized ItemDelegate).

      The workaround is line `onCheckableChanged: checkable = false` added to all checkable delegates driven by models. See also example in the attachment (Qt 6).

      The workaround is needed because on the model data changes the current Qt code rolls back explicitly set 'checkable' to from 'false' to 'true' (and uncheckable delegate is the only way to work with models)

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

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            kaffeine Alexandr Akulich
            Votes:
            0 Vote for this issue
            Watchers:
            2 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes