summaryrefslogtreecommitdiffstats
path: root/examples/declarative/listview/highlight.qml
blob: e707ac04f008b7726101e26252c52bcba106b759 (plain)
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
import Qt 4.6

Rectangle {
    width: 400; height: 300; color: "white"

    // MyPets model is defined in dummydata/MyPetsModel.qml
    // The viewer automatically loads files in dummydata/* to assist
    // development without a real data source.
    // This one contains my pets.
    // Define a delegate component.  A component will be
    // instantiated for each visible item in the list.
    Component {
        id: PetDelegate
        Item {
            id: Wrapper
            width: 200; height: 50
            Column {
                Text { text: 'Name: ' + name }
                Text { text: 'Type: ' + type }
                Text { text: 'Age: ' + age }
            }
            // Use the ListView.isCurrentItem attached property to
            // indent the item if it is the current item.
            states: [
                State {
                    name: "Current"
                    when: Wrapper.ListView.isCurrentItem
                    PropertyChanges { target: Wrapper; x: 10 }
                }
            ]
            transitions: [
                Transition {
                    NumberAnimation {
                        properties: "x"; duration: 200
                    }
                }
            ]
        }
    }
    // Specify a highlight with custom movement.  Note that autoHighlight
    // is set to false in the ListView so that we can control how the
    // highlight moves to the current item.
    Component {
        id: PetHighlight
        Rectangle {
            width: 200; height: 50; color: "#FFFF88"
            y: SpringFollow { source: List1.current.y; spring: 3; damping: 0.1 }
        }
    }
    ListView {
        id: List1
        width: 200; height: parent.height
        model: MyPetsModel; delegate: PetDelegate
        highlight: PetHighlight; autoHighlight: false
        focus: true
    }
}