aboutsummaryrefslogtreecommitdiffstats
path: root/src/quick/doc/snippets
diff options
context:
space:
mode:
authorUlf Hermann <ulf.hermann@qt.io>2025-03-12 11:50:13 +0100
committerUlf Hermann <ulf.hermann@qt.io>2025-03-13 14:43:11 +0100
commitca379b08b2ba634562cbc149d6faddef9f4730bc (patch)
treec089ef42ef87598b651b11198e5fc0f7434c3835 /src/quick/doc/snippets
parent1b72a81ab615e1a6e27063e2cce8baa760784939 (diff)
Doc: Modernize some model/view/delegate snippets
Use required properties where possible and unclutter the formatting. Pick-to: 6.9 6.8 Change-Id: Ib170676892e4eed514fa025d0dc1fd9562ab1a08 Reviewed-by: Sami Shalayel <sami.shalayel@qt.io> Reviewed-by: Shawn Rutledge <shawn.rutledge@qt.io>
Diffstat (limited to 'src/quick/doc/snippets')
-rw-r--r--src/quick/doc/snippets/qml/listview-sections.qml1
-rw-r--r--src/quick/doc/snippets/qml/models/views-models-delegates.qml17
-rw-r--r--src/quick/doc/snippets/qml/repeaters/repeater-grid-index.qml33
3 files changed, 38 insertions, 13 deletions
diff --git a/src/quick/doc/snippets/qml/listview-sections.qml b/src/quick/doc/snippets/qml/listview-sections.qml
index 54fc4dd8c8..afbca76ba2 100644
--- a/src/quick/doc/snippets/qml/listview-sections.qml
+++ b/src/quick/doc/snippets/qml/listview-sections.qml
@@ -23,6 +23,7 @@ ListModel {
Component {
id: nameDelegate
Text {
+ required property string name
text: name;
font.pixelSize: 24
anchors.left: parent.left
diff --git a/src/quick/doc/snippets/qml/models/views-models-delegates.qml b/src/quick/doc/snippets/qml/models/views-models-delegates.qml
index 8a2f0519d6..39b54af3ef 100644
--- a/src/quick/doc/snippets/qml/models/views-models-delegates.qml
+++ b/src/quick/doc/snippets/qml/models/views-models-delegates.qml
@@ -26,10 +26,19 @@ Rectangle {
Component {
id: fruitDelegate
Row {
- id: fruit
- Text { text: " Fruit: " + name; color: fruit.ListView.view.fruit_color }
- Text { text: " Cost: $" + cost }
- Text { text: " Language: " + fruit.ListView.view.model.language }
+ id: fruit
+ required property string name
+ required property real cost
+ Text {
+ text: " Fruit: " + fruit.name
+ color: fruit.ListView.view.fruit_color
+ }
+ Text {
+ text: " Cost: $" + fruit.cost
+ }
+ Text {
+ text: " Language: " + fruit.ListView.view.model.language
+ }
}
}
diff --git a/src/quick/doc/snippets/qml/repeaters/repeater-grid-index.qml b/src/quick/doc/snippets/qml/repeaters/repeater-grid-index.qml
index 945641e37c..29f0f1f558 100644
--- a/src/quick/doc/snippets/qml/repeaters/repeater-grid-index.qml
+++ b/src/quick/doc/snippets/qml/repeaters/repeater-grid-index.qml
@@ -5,19 +5,34 @@
import QtQuick
Rectangle {
- width: 400; height: 400; color: "black"
+ width: 400
+ height: 400
+ color: "black"
Grid {
- x: 5; y: 5
- rows: 5; columns: 5; spacing: 10
+ x: 5
+ y: 5
+ rows: 5
+ columns: 5
+ spacing: 10
- Repeater { model: 24
- Rectangle { width: 70; height: 70
- color: "lightgreen"
+ Repeater {
+ model: 24
+ Rectangle {
+ id: delegate
- Text { text: index
- font.pointSize: 30
- anchors.centerIn: parent } }
+ required property int index
+
+ width: 70
+ height: 70
+ color: "lightgreen"
+
+ Text {
+ text: delegate.index
+ font.pointSize: 30
+ anchors.centerIn: parent
+ }
+ }
}
}
}