Jean-Milost Reymond
Jean-Milost Reymond

Reputation: 1943

Qt Quick - How to draw a text with a colored font?

In Qt Quick, I'm trying to draw a text with a colored font using this code:

Text
{
    FontLoader
    {
        id: ftCustomFont;
        source: "Fonts/Colortube-lWAd.otf"
    }

    textFormat: Text.RichText

    text:
    {
        if (ftCustomFont.status == FontLoader.Ready)
            qsTr("<font face=\"" + ftCustomFont.name + "\">test test test</font>");
        else
        if (ftCustomFont.status == FontLoader.Loading)
            "Loading..."
        else
        if (ftCustomFont.status == FontLoader.Error)
            "Error loading font"
    }
}

The font I'm using above was downloaded here: https://www.fontspace.com/neogrey-creative/colortube

Using this font, I expected that a colored text was drawn, however I get this result:

enter image description here

As you can see, the text is drawn with the correct font, but in black&white. I also tried with several colored font samples, downloaded from several sites, unfortunately none of them could draw a colored text.

Is there a way to notify Qt to use the colored glyphs instead of the B&W ones while the text is drawn? How should I configure my qml code above to achieve a such effect? Or Qt doesn't support the colored fonts at all?

Upvotes: 0

Views: 98

Answers (1)

Soheil Armin
Soheil Armin

Reputation: 2795

It seems that it is not supported as of Qt 5.14. Glypes are loaded but they are filled by colors. I tried to set a transparent color but it does not work either. So, you can submit a bug report.

Upvotes: 1

Related Questions