Details
-
Bug
-
Resolution: Done
-
P2: Important
-
5.6, 6.1.0
-
None
-
-
4f73c07b529d2437e72bfdf4c1a75f83e2bdbe76 (qt/qtquickcontrols2/dev)
Description
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:
- The delegate state always represents the model data.
- On the user action, the delegate requests the model to adjust the data.
- The model validates and performs the request.
- The model notifies the views about the data changes via the standard Qt API (dataChanged signal).
- 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)
Attachments
Issue Links
- is duplicated by
-
QTBUG-103967 Checkbox checkable state is not working when using ListModel with delegates
- Closed
-
QTBUG-105874 QML button: double click does not emit clicked() but changes checked state
- Closed