-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathToggleButton.qml
More file actions
90 lines (80 loc) · 1.94 KB
/
ToggleButton.qml
File metadata and controls
90 lines (80 loc) · 1.94 KB
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
83
84
85
86
87
88
/*
* QML Custom Components
*
* Copyright (C) 2022 <parhamoyan@yahoo.com>
*
*/
import QtQuick 2.0
Item {
id: toggleButton
width: 170
height: 100
state: "OFF"
states: [
State {
name: "OFF"
PropertyChanges {
target: indicator
x: (background.height-indicator.height)/2
}
PropertyChanges {
target: background
color: "#E9E9EA"
}
},
State {
name: "ON"
PropertyChanges {
target: indicator
x: background.width-indicator.width-(background.height-indicator.height)/2
}
PropertyChanges {
target: background
color: "#65C466"
}
}
]
transitions: [
Transition {
from: "*"
to: "*"
PropertyAnimation {
properties: "x"
duration: 200
easing.type: Easing.InOutQuad
}
ColorAnimation {
duration: 200
easing.type: Easing.InOutQuad
}
}
]
Rectangle {
id: background
color: "#E9E9EA"
radius: width/2
border.width: 0
anchors.fill: parent
Rectangle {
id: indicator
x: (background.height-indicator.height)/2
y: (background.height-indicator.height)/2
width: 86
height: 86
color: "#ffffff"
radius: width/2
border.width: 0
}
MouseArea {
id: mouseArea
anchors.fill: parent
cursorShape: Qt.PointingHandCursor
onClicked: {
if (toggleButton.state == "OFF")
toggleButton.state = "ON";
else
toggleButton.state = "OFF";
}
}
}
}