summaryrefslogtreecommitdiffstats
path: root/doc/src/declarative/qdeclarativemodels.qdoc
diff options
context:
space:
mode:
authorQt Continuous Integration System <qt-info@nokia.com>2010-07-16 03:35:55 (GMT)
committerQt Continuous Integration System <qt-info@nokia.com>2010-07-16 03:35:55 (GMT)
commit8d8566d061e26f18e1bde1255fdc1375035c8eaa (patch)
tree7467b6c7742a3d3828b918ecec8a73e1f7998791 /doc/src/declarative/qdeclarativemodels.qdoc
parent6986f382c8d7b49342f47fe00445685945157187 (diff)
parent17e7b024ba01aba0e525f7fd03b9c5c0ed34e7c8 (diff)
downloadQt-8d8566d061e26f18e1bde1255fdc1375035c8eaa.zip
Qt-8d8566d061e26f18e1bde1255fdc1375035c8eaa.tar.gz
Qt-8d8566d061e26f18e1bde1255fdc1375035c8eaa.tar.bz2
Merge branch '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1 into 4.7-integration
* '4.7' of scm.dev.nokia.troll.no:qt/oslo-staging-1: (104 commits) Fixed tst_maketestselftest::tests_pro_files failure remove nasty hack by using a stricter regexp (for language codes) cosmetics: quote the dot in the regexp remove dependency of ts targets on sub-tools add commit-ts target to commit ts files without line number info (re-)add 'untranslated' ts targets more fine-grained ts targets split qt_help out into an own ts target Unbreak the Maemo 5 build after the Symbian fix QNAM HTTP: Fix problem with cached files and metaDataChanged() Add a testcase for QTBUG-11213 to prevent future regressions. Autotest: reenable the NTLM proxy test on tst_QTcpSocket Autotest: add a small, boring test for QAuthenticator Add documentation for the QAuthenticator options. Expose the QAuthenticator map of options in the API. Add a QAuthenticatorPrivate parsing for the headers without QHttpResponseHeader Revert BIC change "Build Qt with option -Zc:wchar_t under MSVC" Fix for tst_qmdisubwindow::fixedMinMaxSize failure on Cocoa Add unit tests for QMimeData. fix qconfig.h reference for shadow builds ...
Diffstat (limited to 'doc/src/declarative/qdeclarativemodels.qdoc')
-rw-r--r--doc/src/declarative/qdeclarativemodels.qdoc73
1 files changed, 73 insertions, 0 deletions
diff --git a/doc/src/declarative/qdeclarativemodels.qdoc b/doc/src/declarative/qdeclarativemodels.qdoc
index b44e6f2..a2f4d3a 100644
--- a/doc/src/declarative/qdeclarativemodels.qdoc
+++ b/doc/src/declarative/qdeclarativemodels.qdoc
@@ -429,4 +429,77 @@ Rectangle {
}
\endcode
+\section1 Accessing Views and Models from Delegates
+
+You can access the view for which a delegate is used, and its
+properties, by using ListView.view in a delegate on a ListView, or
+GridView.view in a delegate on a GridView, etc. In particular, you can
+access the model and its properties by using ListView.view.model.
+
+This is useful when you want to use the same delegate for a number of
+views, for example, but you want decorations or other features to be
+different for each view, and you would like these different settings to
+be properties of each of the views. Similarly, it might be of interest
+to access or show some properties of the model.
+
+In the following example, the delegate shows the property \e{language}
+of the model, and the color of one of the fields depends on the
+property \e{fruit_color} of the view.
+
+\code
+Rectangle {
+ width: 200; height: 200
+
+ ListModel {
+ id: fruitModel
+ property string language: "en"
+ ListElement {
+ name: "Apple"
+ cost: 2.45
+ }
+ ListElement {
+ name: "Orange"
+ cost: 3.25
+ }
+ ListElement {
+ name: "Banana"
+ cost: 1.95
+ }
+ }
+
+ Component {
+ id: fruitDelegate
+ Row {
+ Text { text: " Fruit: " + name; color: ListView.view.fruit_color }
+ Text { text: " Cost: $" + cost }
+ Text { text: " Language: " + ListView.view.model.language }
+ }
+ }
+
+ ListView {
+ property color fruit_color: "green"
+ model: fruitModel
+ delegate: fruitDelegate
+ anchors.fill: parent
+ }
+}
+\endcode
+
+Another important case is when some action (e.g. mouse click) in the
+delegate should update data in the model. In this case you can define
+a function in the model, e.g.:
+
+\code
+ setData(int row, const QString & field_name, QVariant new_value),
+\endcode
+
+...and call it from the delegate using:
+
+\code
+ ListView.view.model.setData(index, field, value)
+\endcode
+
+...assuming that \e{field} holds the name of the field which should be
+updated, and that \e{value} holds the new value.
+
*/