-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathImageButton.qml
56 lines (51 loc) · 1.58 KB
/
ImageButton.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
import QtQuick 2.9
import QtQuick.Controls 2.2
import QtQuick.Controls.Material 2.2
Button {
id: control
property alias source: img.source
property bool rounded: false
property real borderWidth: 8
property real borderRadius: Math.min(width, height)*0.5
property bool selected: false
property string color: Material.background
property string colorPressed: Material.foreground
property string colorHovered: Material.accent
implicitHeight: img.implicitHeight + borderWidth
implicitWidth: img.implicitWidth + borderWidth
background: Rectangle {
id: bg
anchors.centerIn: parent
width: parent.width
height: parent.height
Image {
id: img
anchors.centerIn: parent
width: parent.width - borderWidth
height: parent.height - borderWidth
antialiasing: true
fillMode: Image.PreserveAspectFit
clip: true
}
color: "transparent"
radius: rounded ? borderRadius : 0
border.width: borderWidth
border.color: control.color
states: [
State {
name: "pressed"; when: control.pressed
PropertyChanges {
target: bg.border;
color: colorPressed
}
},
State {
name: "hovered"; when: control.hovered | control.selected
PropertyChanges {
target: bg.border;
color: colorHovered
}
}
]
}
}