CButton.qml 997 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. import QtQuick 2.6
  2. import QtQuick.Controls 2.0
  3. /*
  4. 自定义按钮组件
  5. */
  6. Rectangle {
  7. id: button
  8. signal clicked
  9. property alias text: text.text //创建别名属性text,绑定到内部text元素的text属性上
  10. border.width: 1
  11. border.color: mainAppColor
  12. radius: 3
  13. property real textHeight: height - 2
  14. property real fontHeight: 0.3
  15. property bool pressed: mouse.pressed
  16. property real implicitMargin: (width - text.implicitWidth) / 2
  17. //文本元素
  18. Text {
  19. id: text
  20. anchors.left: parent.left
  21. anchors.right: parent.right
  22. anchors.top: parent.top
  23. height: parent.textHeight
  24. horizontalAlignment: Text.AlignHCenter
  25. verticalAlignment: Text.AlignVCenter
  26. font.pixelSize: height * fontHeight
  27. color: "#ffffff"
  28. font.family: alibaba.name
  29. }
  30. //鼠标交互区域
  31. MouseArea {
  32. id: mouse
  33. anchors.fill: parent
  34. onClicked: button.clicked()
  35. }
  36. }