diff options
-rw-r--r-- | doc/src/declarative/qmlmodels.qdoc | 45 | ||||
-rw-r--r-- | doc/src/snippets/declarative/listview/highlight.qml | 12 |
2 files changed, 51 insertions, 6 deletions
diff --git a/doc/src/declarative/qmlmodels.qdoc b/doc/src/declarative/qmlmodels.qdoc index 6ebb734..45df29b 100644 --- a/doc/src/declarative/qmlmodels.qdoc +++ b/doc/src/declarative/qmlmodels.qdoc @@ -50,12 +50,18 @@ creates an instance for each item in the model. Models may be static, or have items modified, inserted, removed or moved dynamically. Data is provided to the delegate via named data roles which the -delegate may bind to. A special \e index role containing the -index of the item in the model is also available. Models that do -not have named roles will have the data provided via the \e modelData -role. The \e modelData role is also provided for Models that have -only one role. In this case the \e modelData role contains the same -data as the named role. +delegate may bind to. The roles are exposed as properties of the +\model property, though this property is set as a default property +of the delegate so, unless there is a naming clash with a +property in the delegate, the roles are usually accessed unqualified. + +A special \e index role containing the index of the item in the model +is also available. + +Models that do not have named roles will have the data provided via +the \e modelData role. The \e modelData role is also provided for +Models that have only one role. In this case the \e modelData role +contains the same data as the named role. There are a number of QML elements that operate using data models: @@ -189,4 +195,31 @@ ListView { An Object Instance specifies a model with a single Object element. The properties of the object are provided as roles. +The example below creates a list with one item, showing the color of the +\e myText text. Note the use of the \e model property to specify the model +data rather than the \e color property of the Text element in the delegate. + +\code +Rectangle { + Text { + id: myText + text: "Hello" + color: "#dd44ee" + } + + Component { + id: myDelegate + Text { + text: model.color + } + } + ListView { + anchors.fill: parent + anchors.topMargin: 30 + model: myText + delegate: myDelegate + } +} +\endcode + */ diff --git a/doc/src/snippets/declarative/listview/highlight.qml b/doc/src/snippets/declarative/listview/highlight.qml index 2234ee7..7970ede 100644 --- a/doc/src/snippets/declarative/listview/highlight.qml +++ b/doc/src/snippets/declarative/listview/highlight.qml @@ -20,6 +20,18 @@ Rectangle { Text { text: '<b>Name:</b> ' + name } Text { text: '<b>Number:</b> ' + number } } + // Use the ListView.isCurrentItem attached property to + // indent the item if it is the current item. + states: [ + State { + name: "Current" + when: wrapper.ListView.isCurrentItem + PropertyChanges { target: wrapper; x: 10 } + } + ] + transitions: [ + Transition { NumberAnimation { properties: "x"; duration: 200 } } + ] } } //! [0] |