aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorMichael Brasser <mbrasser@ford.com>2019-06-11 20:02:56 -0500
committerMichael Brasser <mbrasser@ford.com>2019-06-11 20:02:56 -0500
commitedb4d0e17fc1c5f94e630f73234f76fa1dbdabf7 (patch)
treec1bf4ee07948bdd3ad68390ad1e587380bff3ebf /src
parent6ee1acd6279749beddb5ecab211e3d314eb11fb3 (diff)
Add simple DelegateChooser example to documentation
Task-number: QTBUG-73964 Change-Id: Ic789839de12e046cc1d8fced75ffa0c93960c165 Reviewed-by: Mitch Curtis <mitch.curtis@qt.io>
Diffstat (limited to 'src')
-rw-r--r--src/qml/types/qqmldelegatecomponent.cpp36
1 files changed, 35 insertions, 1 deletions
diff --git a/src/qml/types/qqmldelegatecomponent.cpp b/src/qml/types/qqmldelegatecomponent.cpp
index 470f6cab6a..d6c7ba6bdd 100644
--- a/src/qml/types/qqmldelegatecomponent.cpp
+++ b/src/qml/types/qqmldelegatecomponent.cpp
@@ -199,11 +199,45 @@ bool QQmlDelegateChoice::match(int row, int column, const QVariant &value) const
The DelegateChooser is a special \l Component type intended for those scenarios where a Component is required
by a view and used as a delegate.
DelegateChooser encapsulates a set of \l {DelegateChoice}s.
- These choices are used determine the delegate that will be instantiated for each
+ These choices are used to determine the delegate that will be instantiated for each
item in the model.
The selection of the choice is performed based on the value that a model item has for \l role,
and also based on index.
+ DelegateChooser is commonly used when a view needs to display a set of delegates that are significantly
+ different from each other. For example, a typical phone settings view might include toggle switches,
+ sliders, radio buttons, and other visualizations based on the type of each setting. In this case, DelegateChooser
+ could provide an easy way to associate a different type of delegate with each setting:
+
+ \qml \QtMinorVersion
+ import QtQuick 2.\1
+ import QtQuick.Controls 2.\1
+ import Qt.labs.qmlmodels 1.0
+
+ ListView {
+ width: 200; height: 400
+
+ ListModel {
+ id: listModel
+ ListElement { type: "info"; ... }
+ ListElement { type: "switch"; ... }
+ ListElement { type: "swipe"; ... }
+ ListElement { type: "switch"; ... }
+ }
+
+ DelegateChooser {
+ id: chooser
+ role: "type"
+ DelegateChoice { roleValue: "info"; ItemDelegate { ... } }
+ DelegateChoice { roleValue: "switch"; SwitchDelegate { ... } }
+ DelegateChoice { roleValue: "swipe"; SwipeDelegate { ... } }
+ }
+
+ model: listModel
+ delegate: chooser
+ }
+ \endqml
+
\note This type is intended to transparently work only with TableView and any DelegateModel-based view.
Views (including user-defined views) that aren't internally based on a DelegateModel need to explicitly support
this type of component to make it function as described.