Hallo,
Ich möchte eine QT Anwendung programmieren welches wie ein Adressbuch
funktioniert. D.h. ich sehe in der ersten Listview nur Vorname Nachname
und dann soll sich eine 2.te Listview öffnen mit der Addresse etc
Hier meine BSP
1 | You want to be able to set the current item of the ListView when it's clicked
|
2 | You want to be able to know when the current selection changes
|
3 | The Qt5 documentation says this about ListView mouse and touch handling:
|
4 |
|
5 | The views handle dragging and flicking of their content, however they do not handle touch interaction with the individual delegates. In order for the delegates to react to touch input, e.g. to set the currentIndex, a MouseArea with the appropriate touch handling logic must be provided by the delegate.
|
6 |
|
7 | Key input will work out-of-the-box but you'll need to explicitly catch the mouse/touch event on the delegate, and change the ListView.currentIndex value based on the index value of the selected delegate item.
|
8 |
|
9 | Here's a full example:
|
10 |
|
11 | import QtQuick 2.4
|
12 | import QtQuick.Window 2.2
|
13 |
|
14 | Window {
|
15 | width: 640
|
16 | height: 480
|
17 | visible: true
|
18 |
|
19 | ListModel {
|
20 | id: model
|
21 | ListElement {
|
22 | name:'abc'
|
23 | number:'123'
|
24 | }
|
25 | ListElement {
|
26 | name:'efg'
|
27 | number:'456'
|
28 | }
|
29 | ListElement {
|
30 | name:'xyz'
|
31 | number:'789'
|
32 | }
|
33 | }
|
34 |
|
35 | ListView {
|
36 | id: list
|
37 | anchors.fill: parent
|
38 | model: model
|
39 | delegate: Component {
|
40 | Item {
|
41 | width: parent.width
|
42 | height: 40
|
43 | Column {
|
44 | Text { text: 'Name:' + name }
|
45 | }
|
46 | MouseArea {
|
47 | anchors.fill: parent
|
48 | onClicked: list.currentIndex = index
|
49 | }
|
50 | }
|
51 | }
|
52 | highlight: Rectangle {
|
53 | color: 'grey'
|
54 | Text {
|
55 | anchors.centerIn: parent
|
56 | text: 'Hello ' + model.get(list.currentIndex).name
|
57 | color: 'white'
|
58 | }
|
59 | }
|
60 | focus: true
|
61 | onCurrentItemChanged: console.log(model.get(list.currentIndex).name + ' selected')
|
62 | }
|
63 | }
|
Sobald ich nun auf einen Namen klicke möchte ich die Nummer und die
Details eingeblendet bekommen am besten in einer neuen qml Datei welche
ich anders formatieren kann.
Gibt es dazu ein bsp?
Danke