-
Notifications
You must be signed in to change notification settings - Fork 9
/
SwitchButton.qml
82 lines (68 loc) · 2.02 KB
/
SwitchButton.qml
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
75
76
77
78
79
80
81
82
import QtQuick 2.7
import QtQuick.Templates 2.0 as T
T.Switch {
id: control
implicitWidth: indicator.implicitWidth
implicitHeight: switchHandle.implicitHeight
property alias circolour: rectangle.color
indicator: Rectangle {
id: switchHandle
implicitWidth: 6 * 4.8
implicitHeight: 6 * 2.6
x: control.leftPadding
anchors.verticalCenter: parent.verticalCenter
radius: 6 * 1.3
color: Qt.darker("#222", 1.2)
border.color: "#fff"
Rectangle {
id: rectangle
width: 6 * 2.6
height: 6 * 2.6
radius: 10 * 1.3
color: Qt.lighter("#222", 1.5)
border.color: "#fff"
}
states: [
State {
name: "off"
when: !control.checked && !control.down
},
State {
name: "on"
when: control.checked && !control.down
PropertyChanges {
target: switchHandle
color: Qt.lighter("#222", 1.5)
border.color: "#fff"
}
PropertyChanges {
target: rectangle
x: parent.width - width
}
},
State {
name: "off_down"
when: !control.checked && control.down
PropertyChanges {
target: rectangle
color: "#fff"
}
},
State {
name: "on_down"
extend: "off_down"
when: control.checked && control.down
PropertyChanges {
target: rectangle
x: parent.width - width
color: "#fff"
}
PropertyChanges {
target: switchHandle
color: "#222"
border.color: "#222"
}
}
]
}
}