Embed fonts[Solved]
-
Hi Guys,
how can i embed fonts in qt from a folder as a resource?
Gaurav
-
Like this?
FontLoader { id: localFont; source: "fonts/whatever.ttf" }It should be possible to add the font into a resource file and then reference it using the qrc://fonts/whatever.ttf syntax if that's what you're asking.
-
hi ,
i'm Struggling over that, what's the Solution ?thanks.
linlin
-
Hi,
FontLoader ia a QML feature.
You can try int QFontDatabase::addApplicationFont ( const QString & fileName ), but I'm not sure, whether it can load from a resource.
Otherwise you can load the resource by hand and call int QFontDatabase::addApplicationFontFromData ( const QByteArray & fontData ) [static].
Here you can find mor information:http://doc.qt.nokia.com/4.7/qfontdatabase.html#addApplicationFont
-
The fonts example demonstrates use:
http://doc.trolltech.com/4.7/declarative-text-fonts-fonts-qml.htmlIf you want to use fonts in a resource, they work identically to images and other things inside a Qt resource file. Just create a new qrc file in Qt Creator (or whatever), add the fonts, then reference it using the qrc:// syntax rather then a raw file:// path one. There's a little documentation on the use of qrc urls here: http://doc.trolltech.com/latest/qdeclarativenetwork.html but I don't recall any specific examples.
-
Thanks guys for the reply.
-
One more quick question is there any way i can include fonts in a folder and give the path in css?
-
On Windows, a font always needs to be installed in the windows fonts dir, but you can go the same way as with resources (load it dynamically with QFontDatabase::addApplicationFont). But at the css, you can just set the font name.
-
hi gaurav, always better to start a new question in a separate thread .. will be easier for everyone to search later :) so can you move this to a new thread