-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path19_arranging_items.qml
167 lines (137 loc) · 2.86 KB
/
19_arranging_items.qml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
// 1
Grid {
x: 15; y: 15; width: 300; height: 300
columns: 2; rows: 2; spacing: 20
Rectangle { width: 125; height: 125; color: "red" }
Rectangle { width: 125; height: 125; color: "green" }
Rectangle { width: 125; height: 125; color: "silver" }
Rectangle { width: 125; height: 125; color: "blue" }
}
// 2
Rectangle {
width: 400; height: 400; color: "black"
Grid {
x: 5; y: 5
rows: 5; columns: 5; spacing: 10
Repeater {
model: 24 // focus here
delegate: Rectangle { // "delegate" is implicit
required property int index // <-- attached property
width: 70; height: 70
color: "lightgreen"
Text {
anchors.centerIn: parent
text: model.index
font.pointSize: 30
}
}
}
}
}
// 3
Rectangle {
width: 400; height: 400; color: "black"
Component {
id: rectangleComponent
Rectangle {
width: 70;
height: 70
color: "lightgreen"
}
}
Grid {
x: 5; y: 5
rows: 5; columns: 5; spacing: 10
Repeater {
model: 24
delegate: rectangleComponent
}
}
}
// 4
Grid {
x: 15; y: 15; width: 300; height: 300
columns: 2; rows: 2; spacing: 20
Repeater {
model: ["red", "green", "silver", "blue"]
delegate: Rectangle {
required property var modelData
width: 125; height: 125; color: modelData // old -> model.modelData
}
}
}
// 5
Grid {
x: 15; y: 15; width: 300; height: 300
columns: 2; rows: 2; spacing: 20
Repeater {
model: [
{
color: "red",
value: 32
},
{
color: "green",
value: 12
},
{
color: "silver",
value: 77
},
{
color: "blue",
value: 1
},
]
delegate: Rectangle {
required property var modelData
width: 125; height: 125; color: modelData.color
Text {
anchors.centerIn: parent
text: modelData.value
font.pointSize: 30
}
}
}
}
// 6
Rectangle {
width: 150; height: 200; color: "white"
ListModel {
id: nameModel
ListElement { age: 41; name: "Alice" }
ListElement { age: 42; name: "Bob" }
ListElement { age: 43; name: "Jane" }
ListElement { age: 44; name: "Victor" }
ListElement { age: 45; name: "Wendy" }
}
Component {
id: nameDelegate
Rectangle {
required property var model
border.color: "black"
border.width: 1
height: name.height + age.height
width: name.width
Column {
Text {
id: name
text: model.name
font.pixelSize: 32
}
Text {
id: age
text: model.age
font.pixelSize: 32
}
}
}
}
Column {
anchors.fill: parent
Repeater {
model: nameModel
delegate: nameDelegate
}
}
}