-
Notifications
You must be signed in to change notification settings - Fork 0
/
MyButton.qml
63 lines (55 loc) · 1.87 KB
/
MyButton.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
import QtQuick 2.6
import QtQuick.Controls 2.1
Element1 {
id: buttonRect
property string text: ""
property alias enabled: btn.enabled
property alias highlighted: btn.highlighted
// set a holdText for buttons that have different functions when pressed as held
property string holdText: ""
// the property buttonHold will then be "true" when the clicked signal is fired.
// it is reset only the next time the button is pressed down.
property bool buttonHold
signal clicked();
// this is fired after a buttonHold when the user fired the "holdText" alternative action
signal clickedHold();
Button {
id: btn
anchors.fill: parent
font.pointSize: 8
flat: true
text: ((buttonRect.holdText != "" && btn.pressed && buttonRect.buttonHold) ? buttonRect.holdText : buttonRect.text)
background: Rectangle {
id: backgr
opacity: enabled ? 1 : 0.3
color: btn.down ? "#f0f0f0" : (btn.highlighted ? "#bbc7d2" : "lightgrey")
radius: 10
}
onClicked: {
animateColor.start()
buttonRect.clicked();
}
onPressed: {
buttonRect.buttonHold = false
}
onPressAndHold: {
if (holdText) {
buttonRect.buttonHold = true
}
}
onReleased: {
if (buttonRect.buttonHold) {
animateColor.start()
buttonRect.clickedHold()
}
}
contentItem: Label {
text: btn.text
font: btn.font
verticalAlignment: Text.AlignVCenter
horizontalAlignment: Text.AlignHCenter
wrapMode: Text.WordWrap
}
PropertyAnimation {id: animateColor; target: backgr; properties: "color"; from:"lightgrey"; to: "lightgrey"; duration: 100}
}
}