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
|
import QtQuick 2.0
Item{
id: root
property QtObject declarativerectangle : null
property QtObject declarativeitem : null
property QtObject bindingTestObject : null
property QtObject bindingThisTestObject : null
property QtObject badRequired: null
property QtObject goodRequired: null
property QtObject bindingAsInitial: null
property bool bindingUsed: false
Component{
id: a
Rectangle {
property Rectangle innerRect: Rectangle { border.width: 20 }
}
}
Component{
id: b
Item{
property bool testBool: false
property int testInt: { return null; }
property QtObject testObject: null
}
}
// test passing in bindings
width: 100
Component {
id: c
Item {
property int testValue
width: 300
}
}
Component {
id: d
Item {
required property int i
}
}
Component {
id: e
Rectangle {}
}
Component.onCompleted: {
root.declarativerectangle = a.createObject(root, {"x":17,"y":17, "color":"white", "border.width":3, "innerRect.border.width": 20});
root.declarativeitem = b.createObject(root, {"x":17,"y":17,"testBool":true,"testInt":17,"testObject":root});
root.bindingTestObject = c.createObject(root, {'testValue': Qt.binding(function(){return width * 3}) }) // use root.width
root.bindingThisTestObject = c.createObject(root, {'testValue': Qt.binding(function(){return this.width * 3}) }) // use width of Item within 'c'
root.badRequired = d.createObject(root, { "not_i": 42 });
root.goodRequired = d.createObject(root, { "i": 42 });
root.bindingAsInitial = e.createObject(root, {color: Qt.binding(() => {
root.bindingUsed = true; return '#ff0000'
})});
}
}
|