Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
I have an application for which I want to use the material style. The material style uses the Roboto font by google, but it needs to be installed on the system. How can I make sure, that the font is available on a system? Use the Qt-Installer framework and install the fonts (if this is even possible)? Or can I tell Qt to look for the fonts in a certain directory relative to the executable? If I simply put them into my resource file, e.g. the Buttons in Material style don't use the correct font (e.g. fall back to Noto which is installed on my linux machine)
Tom_H last edited by
@maxwell31 You have to add it to the font database. Then you can set the default application font with
QFontDatabase fdb; fdb.addApplicationFont(":/res/fonts/myfont.ttf");
Or with a
Adding it to the Font database and using "QGuiApplication::setFont" is working. However, something I wonder: How can I find out the name under which the font is available? Doing this
QFontDatabase::addApplicationFont("qrc:/resources/Roboto-Regular.ttf"); QFontDatabase::addApplicationFont("qrc:/resources/Roboto-Medium.ttf"); QFontDatabase::addApplicationFont("qrc:/resources/Roboto-Light.ttf"); QFontDatabase a; qDebug()<<a.families();
does not show the Roboto fonts in the output.
Ok, the error was that I have to do
qrc:. Actually I don't understand the difference between
instead of qrc:. Actually I don't understand the difference between qrc and :
qrc:/is a url format, wheras
:/is a filepath format
and urls don't work for the addApplicationFont?
urls are expected when the parameter type is also
QUrl(at least mostly this is the case)
But if the parameter is of the type
fileNameyou can assume it expects a file path.
Thanks. So here it expects a fileName, and if the file is in the resources, it should start with :/, alright.