diff options
Diffstat (limited to 'src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc')
-rw-r--r-- | src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc | 32 |
1 files changed, 31 insertions, 1 deletions
diff --git a/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc b/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc index 89b7929755..0c6aaecf42 100644 --- a/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc +++ b/src/quick/doc/src/concepts/modelviewsdata/modelview.qdoc @@ -46,7 +46,8 @@ types for creating models. display the data in a list or a grid. \li \b Delegate - dictates how the data should appear in the view. The delegate takes each data in the model and encapsulates it. The data is -accessible through the delegate. +accessible through the delegate. The delegate can also write data +back into editable models (e.g. in a TextField's onAccepted Handler). \endlist To visualize data, bind the view's \c model property to a model and the @@ -390,6 +391,35 @@ If the model is a string list, the delegate is also exposed to a read-only It is also possible to use a delegate as the template for the items created by a Repeater. This is specified using the \l{Repeater::}{delegate} property. +\section1 Changing Model Data + +To change model data, you can assign updated values to the \c model properties. +The QML ListModel is editable by default whereas C++ models must implement +setData() to become editable. Integer and JavaScript array models are read-only. + +Supposed a \l{QAbstractItemModel} based C++ model that implements the +\l{QAbstractItemModel::}{setData} method is registered as a QML type named +\c EditableModel. Data could then be written to the model like this: + +\qml +ListView { + anchors.fill: parent + model: EditableModel {} + delegate: TextEdit { + width: ListView.view.width + height: 30 + text: model.edit + Keys.onReturnPressed: model.edit = text + } +} +\endqml + +\note The \c edit role is equal to \l Qt::EditRole. See \l{QAbstractItemModel::}{roleNames}() +for the built-in role names. However, real life models would usually register custom roles. + +For more information, visit the \l{qtquick-modelviewsdata-cppmodels.html#changing-model-data}{Using C++ Models with Qt Quick Views} +article. + \section1 Using Transitions Transitions can be used to animate items that are added to, moved within, |