更改 QML 控件的文本颜色 [英] Change text color for QML controls
问题描述
我正在使用一些 QML 控件,例如 GroupBox
和 CheckBox
有与之关联的文本.文本的默认颜色为黑色.但是,我将这些项目放在深色背景上,并且更喜欢使用白色作为文本颜色.这些项目没有颜色属性,所以我不知道该怎么做.
I am using some QML controls like GroupBox
and CheckBox
which have text associated with them. The default color of the text is black. However, I have these items on a dark background and would prefer using white for the text color. These items don't have a color property so I'm not sure what to do.
CheckBox {
text: "Check Me"
}
推荐答案
您需要使用style
属性重新定义 Component
以用于基于 CheckBoxStyle
You need to use the style
property to redefine the Component
to use for the label based on the CheckBoxStyle
import QtQuick 2.1
import QtQuick.Controls 1.0
import QtQuick.Controls.Styles 1.0
Rectangle {
color: "black"
CheckBox {
style: CheckBoxStyle {
label: Text {
color: "white"
text: "check Me"
}
}
}
}
使用 CheckBoxStyle
时,您可能需要重新定义整个组件,而不仅仅是标签属性.
When using CheckBoxStyle
you might have to redefine the whole component and not just the label property.
这篇关于更改 QML 控件的文本颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!