我是 QML 新手,我想个性化我的按钮。我成功改变了背景颜色和边框颜色。但我根本没有成功改变按钮文本的颜色。我看到我们不再使用“样式”来改变样式,而是使用“背景”,但我不明白它的一切。
感谢您的帮助。
Button {
id: buttonAC
text: qsTr("AC")
Layout.fillHeight: true
Layout.fillWidth: true
background: Rectangle {
border.color: "#14191D"
color: "#24292f"
// I want to change text color next
}
/*Text {
text: qsTr("AC")
color: "#F54035"
}*/
}
最佳答案
根据doc
import QtQuick 2.6
import QtQuick.Controls 2.1
Button {
id: control
text: qsTr("Button")
contentItem: Text {
text: control.text
font: control.font
opacity: enabled ? 1.0 : 0.3
color: control.down ? "#17a81a" : "#21be2b"
horizontalAlignment: Text.AlignHCenter
verticalAlignment: Text.AlignVCenter
elide: Text.ElideRight
}
background: Rectangle {
implicitWidth: 100
implicitHeight: 40
opacity: enabled ? 1 : 0.3
border.color: control.down ? "#17a81a" : "#21be2b"
border.width: 1
radius: 2
}
}
关于qt - QML 按钮更改文本颜色,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40823503/