我正在寻找一种使用 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
}
Run Code Online (Sandbox Code Playgroud)
但这只是改变按钮的正常状态,无法找到按下按钮时赋予样式的方法。
在 中ButtonStyle,您可以使用control.hovered和control.pressed来确定按钮何时被悬停或按下。
ButtonStyle {
background: Rectangle {
width: control.width
height: control.height
color: control.pressed ? "gray" : "black"
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2766 次 |
| 最近记录: |