Change text color for QML controls

I use QML controls like GroupBox and CheckBox that have text associated with them. The default text color is black. However, I have these items on a dark background and prefer to use white for text. These elements do not have a color property, so I'm not sure what to do.

 CheckBox { text: "Check Me" } 
+6
source share
3 answers

You need to use the style property to override Component to use for a label based on 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 may need to override the entire component, not just the label property.

+3
source

Have you tried to set it as a complete sub-element of this flag?

 CheckBox { Text { text: "Check Me" color: "red" } } 
+2
source

I had the same problem with GroupBox, so I wanted to post an answer for future reference. The problem can be easily fixed with HTML formatting. For example, to change the color:

 GroupBox{ title: "<font color=\"white\">my title</font>" } 

Size and other formatting options can be changed equally.

0
source

Source: https://habr.com/ru/post/952619/


All Articles