Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML FontLoader not working

Tags:

c++

fonts

qt

qml

I'm trying to use QML's built-in FontLoader element to load a custom font for our application without success.

I've tried using both OTF and TTF fonts with identical results.

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

This is what it should look like:

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
    }
}
like image 877
Andrew Avatar asked Feb 23 '13 21:02

Andrew


1 Answers

I've had headaches with Qt/QML's font handling. Fonts with "various sub styles" seem to be the fundamental problem. When I absolutely needed to get at one particular problem font style in Qt, creating a custom version with fontforge of the font where the wanted style was renamed "normal" seemed to work.

like image 57
timday Avatar answered Sep 23 '22 10:09

timday