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
|
// Copyright (C) 2025 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Qt.labs.qmlmodels
Page {
id: page
GridLayout {
anchors.fill: parent
anchors.margins: 10
Label {
wrapMode: Label.Wrap
horizontalAlignment: Qt.AlignHCenter
text: qsTr("TreeView provides a hierarchical view for displaying and "
+ "navigating tree-structured data, allowing users to expand and "
+ "collapse nodes to explore parent-child relationships within a model")
Layout.fillWidth: true
Layout.columnSpan: 2
}
Item {
implicitHeight: 40
Layout.columnSpan: 2
Layout.row: 1
}
HorizontalHeaderView {
clip: true
enabled: !GalleryConfig.disabled
syncView: treeView
model: [qsTr("Location")]
Layout.column: 1
Layout.row: 2
Layout.fillWidth: true
}
VerticalHeaderView {
clip: true
enabled: !GalleryConfig.disabled
syncView: treeView
model: Array.from({length: treeView.rows}, (v, k) => k + 1)
Layout.column: 0
Layout.row: 3
Layout.fillHeight: true
}
TreeView {
id: treeView
clip: true
enabled: !GalleryConfig.disabled
rowSpacing: 2
model: treeModel
Layout.column: 1
Layout.row: 3
Layout.fillWidth: true
Layout.fillHeight: true
selectionModel: ItemSelectionModel {}
delegate: TreeViewDelegate { }
columnWidthProvider: (column) => column === 0 ? treeView.width : 0
Component.onCompleted: expandRecursively()
}
}
TreeModel {
id: treeModel
TableModelColumn { display: "location" }
rows: [
{
location: qsTr("America"),
rows: [
{ location: qsTr("Brazil") },
{
location: qsTr("Canada"),
rows: [
{ location: qsTr("Calgary") },
{ location: qsTr("Vancouver") }
]
}
]
},
{ location: qsTr("Asia") },
{
location: qsTr("Europe"),
rows: [
{
location: qsTr("Italy"),
rows: [
{ location: qsTr("Milan") },
{ location: qsTr("Rome") }
]
},
{ location: qsTr("Portugal") }
]
}
]
}
}
|