QML_自定义按钮
效果图:
实现过程:
import QtQuick 2.0
import QtQuick.Controls 2.12
Button {
id: homebtn
width: 150
height: 100
autoRepeat: false
flat: false
text: qsTr("白平衡")
property alias iconpath: btnico.source
// checkable: true
background: Rectangle { //设置整个按钮得背景色,按下时按钮背景色是白色
width: parent.width
height: parent.height
color: "#00000000"
Image {
source: (homebtn.down | homebtn.checked) ? "../../images/homebtnico_h.png" : "../../images/homebtnico.png"
anchors.centerIn: parent
}
}
contentItem: Item {
Image {
id: btnico
anchors.horizontalCenter: parent.horizontalCenter
anchors.top: parent.top
anchors.topMargin: 7
source: "../../images/homeawbico.png"
}
Text {
anchors.horizontalCenter: parent.horizontalCenter
anchors.bottom: parent.bottom
anchors.bottomMargin: 5
color: "#2288E2"
text: homebtn.text
font.bold: true
font.pixelSize: 18
}
}
}
引用:
Homebtn {
text: qsTr("亮度")
iconpath: "../../images/homebrightness.png"
onClicked: {
//popup_bright.open()
}
}