aboutsummaryrefslogtreecommitdiffstats
path: root/tests/auto/qmltest/listview/data/MultiDelegate.qml
blob: 5b7f9d12acd4e7bdeb42d5cf5823966ad44abe22 (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
58
59
// Copyright (C) 2018 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause

import QtQuick 2.12
import QtQml.Models 2.12
import Qt.labs.qmlmodels 1.0

ListView {
    width: 400
    height: 400
    model: ListModel {
        ListElement { dataType: "rect"; color: "red" }
        ListElement { dataType: "image"; source: "logo.png" }
        ListElement { dataType: "text"; text: "Hello" }
        ListElement { dataType: "text"; text: "World" }
        ListElement { dataType: "rect"; color: "green" }
        ListElement { dataType: "image"; source: "logo.png" }
        ListElement { dataType: "rect"; color: "blue" }
        ListElement { dataType: "" }
    }

    delegate: DelegateChooser {
        role: "dataType"
        DelegateChoice {
            roleValue: "image"
            delegate: Image {
                width: parent.width
                height: 50
                fillMode: Image.PreserveAspectFit
                source: model.source
            }
        }
        DelegateChoice {
            roleValue: "rect"
            delegate: Rectangle {
                width: parent.width
                height: 50
                color: model.color
            }
        }
        DelegateChoice {
            roleValue: "text"
            delegate: Text {
                width: parent.width
                height: 50
                horizontalAlignment: Text.AlignHCenter
                verticalAlignment: Text.AlignVCenter
                text: model.text
            }
        }

        DelegateChoice {
            delegate: Item {
                    width: parent.width
                    height: 50
                }
        }
    }
}