Closed fperillo closed 6 years ago
The font files should be bundled with the library as resources.
See components/resources.qrc
:
<RCC>
<qresource prefix="/fonts">
<file>../fonts/Roboto/Roboto-Black.ttf</file>
<file>../fonts/Roboto/Roboto-Bold.ttf</file>
<file>../fonts/Roboto/Roboto-Medium.ttf</file>
<file>../fonts/Roboto/Roboto-Regular.ttf</file>
<file>../fonts/Roboto/Roboto-Light.ttf</file>
<file>../fonts/Roboto/Roboto-Thin.ttf</file>
</qresource>
...
These are then loaded by the style class (QtMaterialStyle). See qtmaterialstyle.cpp
, line 23:
QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Regular.ttf");
QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Medium.ttf");
QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Bold.ttf");
I don't have the font installed on my system, no.
I used the unix switch for grep on a windows workstation... no dir recursion... sorry about this.
This evening I will try on my home notebook, and will try this code snippet to see what happens with the fonts: https://bugreports.qt.io/browse/QTBUG-61520
I still think that setPointSize call should not be necessary it the correct font is returned from the FontDatabase.
I confirm there is a problem with the font loading. Which one is Roboto?
I think the problem is in the resource file... I'm not even sure you are using roboto font due to a mismatch in the path name... QFontDatabase::addApplicationFont(":/material/fonts/Roboto/Roboto-Regular.ttf");
See the changes in the respource file: https://github.com/fperillo/qt-material-widgets/commit/1bfb9990054121d8720df170d364282c958a14da and where I add the fonts using the aliases
What if you put the fonts in the same directory as the icons? I mean, just copy the whole fonts directory into components/
and then change the path in the resource file from ../fonts/Roboto
to fonts/Roboto
.
The resource path is not a one-to-one mapping to the file system path, because of how the resource system works in Qt. See http://doc.qt.io/qt-5/resources.html. (The IDE complains if I try to use an incorrect resource path.)
I'll try on a different machine also when I get the chance, to see if I can figure out what the problem is.
An alias should be used in the resource file, in this way:
then load in this way: QFontDatabase::addApplicationFont( ":/fonts/rmedium" );
This is an official way to load resources via aliases.
I then created font via: QFont font("Roboto", 14, iFontWeight ) where f.e. iFontWeight = QFont::Bold
Ok, I think I understand now. Does https://github.com/laserpants/qt-material-widgets/commit/2ee5d6dd5de94e8bade310330a6f8e651edbb60e work or?
It works now :-)
Thank you
In my fork I pushed a first try at ListItem. It is a test.. and both worked and not worked...
As you can see, the font is "strange"... I think that Qt is stretching it a bit...
I did some more tests and noticed that I don't have Roboto font installed on my workstation. And that the library doesn't load them with ::addApplicationFont. Also loading the font, I still have problems, the font is not used. If I ask for an installed font, it is used without problem. Also trying to load another external font I get the default font....
Actually, wherever you have to use this code snippet:
means that font object has no size 16 and you have to force it....
I don't know what other test to do...
Do you have the font installed?