QML FontLoader not working

I am trying to use the FontLoader QML inline element to load a custom font for our application without success.

I tried using both OTF and TTF fonts with the same results.

Fonts are in the same directory as the project files. There is only one QML, the main one, where this FontLoader lives.

Here's how it should look:

sample screenshot

Here is my code:

import QtQuick 2.0 Rectangle { width: 360 height: 360 FontLoader { id: cFontLoader source: "./fontlol.ttf" } Text { id: testText anchors.centerIn: parent text: "Hello Fonts!" font.family: cFontLoader.name font.pointSize: 32 } } 
+7
source share
4 answers

I had headaches with handling Qt / QML fonts. Fonts with "different subtypes" appear to be a fundamental problem . When I absolutely needed to sort out one font style problem in Qt, creating a custom version with a fontforge font in which the desired style was renamed “normal” seemed to work.

+6
source

The QML text component recognizes fonts by the font name. However, if you download different types of fonts, usually the font name in the font metadata is the same.

The text component has a font.styleName property that can be used to access various font types:

 FontLoader{id: loader source: "AwesomeFont-Bold.ttf"} Text { font.family: loader.name font.styleName: "Bold" } 
0
source

I also tried this problem, but in my case it was because I added the name property. When I delete the name, we begin to show the font.

-one
source

FontLoader just works fine with me

  FontLoader{id:fixedFont; name: "Digital-7"} Text { text:"Hello world" font.family: fixedFont.name } 

see here for more details

-2
source

All Articles