-
Notifications
You must be signed in to change notification settings - Fork 5
/
ImgButton.qml
67 lines (61 loc) · 1.54 KB
/
ImgButton.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
import QtQuick 2.0
import QtGraphicalEffects 1.0
Rectangle {
id: button
radius: 5
color: focus ? "#33000000" : "transparent"
width: 30
height: 30
property url normalImg: ""
property url hoverImg: normalImg
property url pressImg: normalImg
property color normalColor: "transparent"
property color hoverColor: normalColor
property color pressColor: normalColor
signal clicked()
signal enterPressed()
onNormalImgChanged: img.source = normalImg
Image {
id: img
width: parent.width
height: parent.height
anchors.centerIn: parent
}
ColorOverlay {
id: imgOverlay
anchors.fill: img
source: img
color: normalColor
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: {
img.source = hoverImg
imgOverlay.color = hoverColor
}
onPressed: {
img.source = pressImg
imgOverlay.color = pressColor
}
onExited: {
img.source = normalImg
imgOverlay.color = normalColor
}
onReleased: {
img.source = normalImg
imgOverlay.color = normalColor
}
onClicked: button.clicked()
}
Component.onCompleted: {
img.source = normalImg
imgOverlay.color = normalColor
}
Keys.onPressed: {
if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter) {
button.clicked()
button.enterPressed()
}
}
}