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
|
// Copyright (C) 2017 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GPL-3.0-only
import QtQuick 2.0
Rectangle {
height: 400
width: 300
property int sets: 1
ListModel {
id: listmodel
Component.onCompleted: addNames()
}
ListView {
id: listview
model: listmodel
height: 300
width: 200
clip: true
anchors.centerIn: parent
section.delegate: del1
section.criteria: ViewSection.FirstCharacter
section.property: "name"
delegate: Rectangle {
height: 50
width: 200
color: "gold"
border.color: "black"
Text {
anchors.centerIn: parent
text: model.name+" ["+model.id+"]"
color: "black"
font.bold: true
}
}
}
function addNames() {
var names = ["Alpha","Bravo","Charlie","Delta","Echo","Foxtrot",
"Golf","Hotel","India","Juliet","Kilo","Lima","Mike",
"November","Oscar","Papa","Quebec","Romeo","Sierra","Tango",
"Uniform","Victor","Whiskey","XRay","Yankee","Zulu"];
for (var i=0;i<names.length;++i)
listmodel.insert(sets*i, {"name":names[i], "id": "id"+i});
sets++;
}
Component {
id: del1
Rectangle {
height: 50
width: 200
color: "white"
border.color: "black"
border.width: 3
Text {
anchors.centerIn: parent
text: section
}
}
}
Component {
id: del2
Rectangle {
height: 50
width: 200
color: "lightsteelblue"
border.color: "orange"
Text {
anchors.centerIn: parent
text: section
}
}
}
Rectangle {
anchors.fill: listview
color: "transparent"
border.color: "green"
border.width: 3
}
Row {
spacing: 3
Rectangle {
height: 40
width: 70
color: "blue"
Text {
color: "white"
anchors.centerIn: parent
text: "Criteria"
}
radius: 5
MouseArea {
anchors.fill: parent
onClicked: {
listview.section.criteria = listview.section.criteria == ViewSection.FirstCharacter ?
ViewSection.FullString : ViewSection.FirstCharacter
}
}
}
Rectangle {
height: 40
width: 70
color: "blue"
Text {
color: "white"
anchors.centerIn: parent
text: "Property"
}
radius: 5
MouseArea {
anchors.fill: parent
onClicked: {
listview.section.property = listview.section.property == "name" ? "id" : "name";
console.log(listview.section.property)
}
}
}
Rectangle {
height: 40
width: 75
color: "blue"
Text {
color: "white"
anchors.centerIn: parent
text: "Delegate"
}
radius: 5
MouseArea {
anchors.fill: parent
onClicked: {
console.log("Change delegate")
listview.section.delegate = listview.section.delegate == del1 ? del2 : del1
}
}
}
Rectangle {
height: 40
width: 40
color: "blue"
Text {
color: "white"
anchors.centerIn: parent
text: "+"
font.bold: true
}
radius: 5
MouseArea {
anchors.fill: parent
onClicked: { addNames(); }
}
}
}
}
|