PDA

View Full Version : Load fonts from disk.



catmasik
14th July 2015, 11:39
Environment: Qt 5.5, Win7

I tried to insert into your QML-project custom font.


FontLoader {
id: customFont
source: "f:/QT/MyProjects/TEST4/1.ttf"
}

TextArea {
font.family: customFont.name
}

I get the message: QML FontLoader: Cannot load font: "f:/QT/MyProjects/TEST4/1.ttf"

It turned out that this code loads fonts only from the network ( I checked it and it really works without problems )
Please tell me how to load fonts in qml from the disk.

anda_skoa
14th July 2015, 12:20
Have you tried passing the filename as a file: URI?

E.g. assuming that the QML file is in the same directory as the font, something like



source: Qr.resolveUrl("1.ttf");


Cheers,
_

catmasik
14th July 2015, 13:19
Following your advice, I tried to place the font-file in all projects folders (that Qt found it for sure) and wrote:


source: Qt.resolvedUrl("1.ttf");

but i got the same: QML FontLoader: Cannot load font: "qrc:/1.ttf"

anda_skoa
14th July 2015, 14:53
Well, your QML file is apparently not loaded from disk but from the Qt resource system.
resolveUrl() creates an URL relative to the QML file.

You can put the font into the resource as well, or use a different way to construct the file URI for the on-disk file.

Cheers,
_

catmasik
14th July 2015, 16:25
Well, your QML file is apparently not loaded from disk but from the Qt resource system.
resolveUrl() creates an URL relative to the QML file.

You can put the font into the resource as well, or use a different way to construct the file URI for the on-disk file.

Cheers,
_



Yes! After i add the font-file into the resource problem disappeared. Thanks for the help!