繁体   English   中英

所有Qt快速按钮控件状态的自定义样式

[英]Custom style for all Qt Quick Button Control states

我正在寻找一种使用QML为按钮的所有状态创建自定义样式的方法。 到目前为止,我只发现了以下方法来创建可应用于多个按钮的样式

Component {
  id: leftButtonStyle

  ButtonStyle {

      background: Rectangle {
          width: control.width
          height: control.height
          color: "black"
      }

      label: Text {
          font.family: "Helvetica"
          font.pointSize: 10
          color: "#949599"
          text: control.text
      }
  }

}

Button {
    text:"Button One"
    style: leftButtonStyle
}

Button {
        text:"Button Two"
        style: leftButtonStyle
}

但是,这仅会更改按钮的正常状态,并且在按下按钮时找不到找到样式的方法。

ButtonStyle ,可以使用control.hoveredcontrol.pressed确定何时悬停或按下按钮。

  ButtonStyle {
     background: Rectangle {
        width: control.width
        height: control.height
        color: control.pressed ? "gray" : "black"
     }
  }

您可以查看名为QtQuick Control Touch Gallery的示例项目,也可以在此处查看在线版本http://qt-project.org/doc/qt-5/qtquickcontrols-touch-content-buttonpage-qml.html

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM