1234567891011121314151617181920212223242526272829303132333435363738 |
- import QtQuick 2.6
- import QtQuick.Controls 2.0
- /*
- 自定义按钮组件
- */
- Rectangle {
- id: button
- signal clicked
- property alias text: text.text //创建别名属性text,绑定到内部text元素的text属性上
- border.width: 1
- border.color: mainAppColor
- radius: 3
- property real textHeight: height - 2
- property real fontHeight: 0.3
- property bool pressed: mouse.pressed
- property real implicitMargin: (width - text.implicitWidth) / 2
- //文本元素
- Text {
- id: text
- anchors.left: parent.left
- anchors.right: parent.right
- anchors.top: parent.top
- height: parent.textHeight
- horizontalAlignment: Text.AlignHCenter
- verticalAlignment: Text.AlignVCenter
- font.pixelSize: height * fontHeight
- color: "#ffffff"
- font.family: alibaba.name
- }
- //鼠标交互区域
- MouseArea {
- id: mouse
- anchors.fill: parent
- onClicked: button.clicked()
- }
- }
|