Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to add color on specific words on QML Text

Tags:

javascript

qt

qml

Hello i would like to add different color on specific words of a string to be used in QML Text

Text {

    text: "Blue Red Yellow Green"

}

I know that you can add color to the whole text, but i would like to add specific color on specific words. is this possible? and how is it achieved?

like image 447
Jake quin Avatar asked Mar 05 '19 13:03

Jake quin


People also ask

How do you apply color to text?

Go to Format > Font > Font. + D to open the Font dialog box. Select the arrow next to Font color, and then choose a color.

How do you wrap text in QML?

By default, Text will display the text as a single line unless it contains embedded newlines. To wrap the line, set the wrapMode property and give the text an explicit width for it to wrap to.


1 Answers

Text items can display both plain and rich text. For example you can have:

Text {
    text: "<font color=\"#0000FF\">Blue</font> <font color=\"#FF0000\">Red</font>"
}
like image 182
Nejat Avatar answered Oct 03 '22 04:10

Nejat