forked from m-wynn/sddm_wynn-theme
-
Notifications
You must be signed in to change notification settings - Fork 0
/
ImgButton.qml
43 lines (38 loc) · 985 Bytes
/
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
import QtQuick 2.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
signal clicked()
signal enterPressed()
onNormalImgChanged: img.source = normalImg
Image {
id: img
width: parent.width
height: parent.height
anchors.centerIn: parent
}
MouseArea {
anchors.fill: parent
hoverEnabled: true
onEntered: img.source = hoverImg
onPressed: img.source = pressImg
onExited: img.source = normalImg
onReleased: img.source = normalImg
onClicked: button.clicked()
}
Component.onCompleted: {
img.source = normalImg
}
Keys.onPressed: {
if (event.key == Qt.Key_Return || event.key == Qt.Key_Enter) {
button.clicked()
button.enterPressed()
}
}
}