-
Notifications
You must be signed in to change notification settings - Fork 0
/
20_listview.qml
104 lines (87 loc) · 2.08 KB
/
20_listview.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
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
}
}
// Component.onCompleted: console.log("Welcome", model.name)
// Component.onDestruction: console.log("Goodbye", model.name)
}
}
ListView {
anchors.fill: parent
model: nameModel
delegate: nameDelegate
clip: true
}
}
// customization
Rectangle {
width: 150; height: 220; color: "white"
ListModel {
id: nameModel
ListElement { name: "Alice" }
ListElement { name: "Bob" }
ListElement { name: "Jane" }
ListElement { name: "Harry" }
ListElement { name: "Wendy" }
}
Component {
id: nameDelegate
Text {
readonly property ListView __lv: ListView.view
width: parent.width
text: model.name;
font.pixelSize: 32
MouseArea {
anchors.fill: parent
onClicked: __lv.currentIndex = model.index
}
}
}
ListView {
anchors.fill: parent
model: nameModel
delegate: nameDelegate
focus: true
clip: true
header: Rectangle {
anchors { left: parent.left; right: parent.right }
height: 10
color: "pink"
}
footer: Rectangle {
anchors { left: parent.left; right: parent.right }
height: 10
color: "lightblue"
}
highlight: Rectangle {
anchors { left: parent.left; right: parent.right }
color: "lightgray"
}
}
}