aboutsummaryrefslogtreecommitdiffstats
path: root/qt-qml/tests/manual/qml-syntax/prop.qml
blob: e52bc7ed6a88dc4d85c1e5695c1ca3b621b26237 (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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
// Copyright (C) 2024 The Qt Company Ltd.
// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR LGPL-3.0-only

import QtQuick

// [default] [required] [readonly] property <propertyType> <propertyName>
// https://doc.qt.io/qt-6/qtqml-syntax-objectattributes.html

Window {
    // qml types
    property int height: 0
    property int height : 0
    property string name: "abcd"
    property color color: "#121212" // comment
    property point value: Qt.point(1, 2)
    property list<int> value: [1, 2, 3, 4]

    // default
    default property var someText

    // required
    Component {
        id: _delegate

        Item {
            required property int point
            required property string name
            required property list<int> value
        }
    }

    // readonly
    readonly property color myvalue: Qt.rgba(1, 1, 1, 1)
    readonly property list<int> value: [1, 2, 3, 4]

    // alias
    property alias text: _text.text

    // without initial value
    property color nextColor
    property list<int> value

    // props in child object
    Rectangle {
        property int animatedHeight: 0
        property string name: "abcd"

        width: 100
        height: 100
        gradient: Gradient {
            GradientStop { position: 0.0; color: "yellow" }
            GradientStop { position: 1.0; color: "green" }
        }

        opacity: 1.0

        Rectangle {
            id: child
        }
    }

    // make property to a required one
    Rectangle {
        required color
    }

    // others
    property list<int> value: [
        1, 2, 3, 4
    ]

    property Model value1: Model { }
    property Model value2: Model { }
}