qml: 自定义按钮-- 仿QML自带控件;

时间:2023-03-09 13:23:05
qml: 自定义按钮-- 仿QML自带控件;
import QtQuick 2.0

Rectangle {
id: btn;
width:;
height:;
radius:;
border.color: "#A3A3A3";
border.width:;
property alias text:btnTxt.text;
Text {
id: btnTxt;
anchors.centerIn: parent;
text: qsTr("text")
}
Gradient{
id: grad;
GradientStop{ position: 0.0; color: "#FDFDFD";}
GradientStop{ position: 0.5; color: "#EFEFEF"; }
GradientStop{ position: 1.0; color: "#E3E3E3";}
}
gradient: grad;
MouseArea{
anchors.fill: parent;
onPressed: {
console.log("clicked")
btn.color = "#D1D1D1"
btn.gradient = undefined;
}
onReleased:{
console.log("release")
btn.color = "tansparent";
btn.gradient = grad;
}
}
}