qml: 自定义按钮-- 仿QML自带控件;
import QtQuick 2.0 Rectangle { id: btn; width: 50; height: 20; radius: 2; border.color: "#A3A3A3"; border.width: 1; 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; } } }