Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

problems with font (introducing ListItem) #24

Closed
fperillo opened this issue Oct 6, 2017 · 10 comments
Closed

problems with font (introducing ListItem) #24

fperillo opened this issue Oct 6, 2017 · 10 comments

Comments

@fperillo
Copy link
Contributor

fperillo commented Oct 6, 2017

In my fork I pushed a first try at ListItem. It is a test.. and both worked and not worked...
one-line_listitem

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:

   QFont font(db.font("Roboto", "Regular", 16));
   font.setPointSize(16); // it should not be necessary

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?

@laserpants
Copy link
Owner

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");

@laserpants
Copy link
Owner

I don't have the font installed on my system, no.

@fperillo
Copy link
Contributor Author

fperillo commented Oct 6, 2017

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.

@fperillo
Copy link
Contributor Author

fperillo commented Oct 6, 2017

I confirm there is a problem with the font loading.
which-is-roboto
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:
fperillo@1bfb999
and where I add the fonts using the aliases

@laserpants
Copy link
Owner

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.

@laserpants
Copy link
Owner

laserpants commented Oct 6, 2017

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.)

@laserpants
Copy link
Owner

I'll try on a different machine also when I get the chance, to see if I can figure out what the problem is.

@fperillo
Copy link
Contributor Author

fperillo commented Oct 6, 2017

An alias should be used in the resource file, in this way:
../fonts/Roboto/Roboto-Medium.ttf

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

@laserpants
Copy link
Owner

Ok, I think I understand now. Does 2ee5d6d work or?

@fperillo
Copy link
Contributor Author

fperillo commented Oct 6, 2017

It works now :-)

Thank you

@fperillo fperillo closed this as completed Oct 6, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants