Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Change text color for QML controls

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"
}
like image 833
roundtheworld Avatar asked Aug 27 '13 20:08

roundtheworld


People also ask

How do you wrap text in QML?

To wrap the line, set the wrapMode property and give the text an explicit width for it to wrap to.

What is difference between Qt and QML?

QML is the language; its JavaScript runtime is the custom V4 engine, since Qt 5.2; and Qt Quick is the 2D scene graph and the UI framework based on it. These are all part of the Qt Declarative module, while the technology is no longer called Qt Declarative.

What is elide in QML?

The elide property can alternatively be used to fit a single line of plain text to a set width. Note that the Supported HTML Subset is limited. Also, if the text contains HTML img tags that load remote images, the text is reloaded. Text provides read-only text.


2 Answers

Have you tried setting it as an entire sub-element of the checkbox?

CheckBox {

    Text {
        text: "Check Me"
        color: "red"
    }
}
like image 120
Calum Murray Avatar answered Sep 19 '22 19:09

Calum Murray


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.

like image 41
luffy Avatar answered Sep 21 '22 19:09

luffy