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"
}
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"
}
}
}
}
When using CheckBoxStyle
you might have to redefine the whole component and not just the label property.
I had the same problem with GroupBox so I wanted to post an answer for future reference. The problem can easily be fixed using HTML formatting. For instance to change the color:
GroupBox{
title: "<font color=\"white\">my title</font>"
}
Size and other formatting parameters can be changed the same way.
Have you tried setting it as an entire sub-element of the checkbox?
CheckBox {
Text {
text: "Check Me"
color: "red"
}
}
来源:https://stackoverflow.com/questions/18474447/change-text-color-for-qml-controls