aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/snippets/qml
diff options
context:
space:
mode:
authorMitch Curtis <mitch.curtis@qt.io>2024-11-19 10:33:58 +0800
committerMitch Curtis <mitch.curtis@qt.io>2024-11-28 16:40:47 +0800
commit473fc5005e2811347f00679e56e90ec0915f8041 (patch)
tree24b6b1e16872e6873f8a8574339bd0cf44528b27 /src/quick/doc/snippets/qml
parent433a330dfb6bf75bf475fac25be287c18e18427e (diff)
Doc: add "Avoid Storing State in Delegates" section to ListView's docs
This is mentioned in a couple of places, so add a dedicated section and link to it. Also add a section to the Qt Quick best practices page. Pick-to: 6.5 6.8 Change-Id: I0ba528e6c37b0c9c82ca1847817251f176b7f978 Reviewed-by: Ulf Hermann <ulf.hermann@qt.io>
Diffstat (limited to 'src/quick/doc/snippets/qml')
-rw-r--r--src/quick/doc/snippets/qml/listview/stateInDelegate.qml20
-rw-r--r--src/quick/doc/snippets/qml/listview/stateInModel.qml26
2 files changed, 46 insertions, 0 deletions
diff --git a/src/quick/doc/snippets/qml/listview/stateInDelegate.qml b/src/quick/doc/snippets/qml/listview/stateInDelegate.qml
new file mode 100644
index 0000000000..29d8d3e7c2
--- /dev/null
+++ b/src/quick/doc/snippets/qml/listview/stateInDelegate.qml
@@ -0,0 +1,20 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Controls.Basic
+
+//! [ListView]
+ListView {
+ anchors.fill: parent
+ model: 3
+ delegate: CheckDelegate {
+ text: qsTr("Channel %1").arg(index + 1)
+
+ required property int index
+ property bool channelActivated
+
+ onClicked: channelActivated = checked
+ }
+}
+//! [ListView]
diff --git a/src/quick/doc/snippets/qml/listview/stateInModel.qml b/src/quick/doc/snippets/qml/listview/stateInModel.qml
new file mode 100644
index 0000000000..56b2792140
--- /dev/null
+++ b/src/quick/doc/snippets/qml/listview/stateInModel.qml
@@ -0,0 +1,26 @@
+// Copyright (C) 2024 The Qt Company Ltd.
+// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
+
+import QtQuick
+import QtQuick.Controls.Basic
+
+//! [ListView]
+ListView {
+ anchors.fill: parent
+ model: ListModel {
+ ListElement {
+ channelActivated: true
+ }
+ // ...
+ }
+ delegate: CheckDelegate {
+ text: qsTr("Channel %1").arg(index + 1)
+ checked: model.channelActivated
+
+ required property int index
+ required property var model
+
+ onClicked: model.channelActivated = checked
+ }
+}
+//! [ListView]