Skip to content

Cannot use both regular and solid fonts together in the same Qt/QML application #12787

Closed

Description

@mhoeher

I often use Font Awesome in Qt/QML applications. In v4, this was quite straightforward, all that needed to be done was using a FontLoader and then set the font.family attribute of text elements to the font family (which could be retrieved via the FontLoader).

With v5, we now have several font files (e.g. there are 3 *.ttf files in the Free version). Generally, it is possible to use multiple FontLoaders to load all of them. However, I noticed that the font family for the regular and solid variants are the same. Hence, I cannot easily switch between the two by setting the font.family attribute of text objects.

I would have expected to be able to select the variant by one of the following:

  • Setting the font.weight property. This did not work out for some reasons - maybe a Qt issue?
  • Setting the font.styleName property, i.e. Solid vs Regular. However, this also did not work (because all the font files are set to Regular).

For the time being, I worked around the issue by editing the file fa-solid-900.ttf with FontForge and setting the font family to Font Awesome 5 Free Solid. With the modified *.ttf file I can easily switch between the two styles in my QML application. It would however be cool if Font Awesome would work out of the box with Qt/QML ;-)

Thanks for considering!

Btw: The brands font file seems to work just fine, however, this is probably due to it uses a different font family name compared to the other two.

Activity

  1. tagliala commented on Apr 6, 2018

    @tagliala
    Member

    Hi!

    Thanks for being part of the Font Awesome Community.

    Sorry but I cannot help. Let's wait for some feedback by the community

    Setting the font.weight property. This did not work out for some reasons - maybe a Qt issue?

    Please check with another font (with separate files for each style)

    Setting the font.styleName property, i.e. Solid vs Regular. However, this also did not work (because all the font files are set to Regular).

    @robmadole is there something we can do about this?

  2. mhoeher commented on Apr 6, 2018

    @mhoeher
    Author

    Hi @tagliala,

    thanks for the hint! I tried to reproduce this with another Font (I tried with Comfortaa) by doing the following:

    1. I downloaded the font and unzipped it.
    2. I put a file font-weight-comfortaa.qml file into the unzipped folder.
    3. I ran qmlscene font-weight-comfortaa.qml.

    The results:
    On standard output it prints:

    qml: Comfortaa
    qml: Comfortaa
    

    as expected. And the rendering is as follows:

    image

    Which looks as expected. Then, I tried the same with Font Awesome:

    1. Downloaded and extracted.
    2. Put a file font-weight-fontawesome.qml into the folder /web-fonts-with-css/webfonts/.
    3. I ran qmlscene font-weight-fontawesome.qml.

    The result: On standard out it prints:

    qml: Font Awesome 5 Free
    qml: Font Awesome 5 Free

    And the result is this:

    image

    Here, my expectation would have been that the lighter variants would use the icons from the regular font while the bolder ones use the one from the solid one.

  3. robmadole commented on Apr 10, 2018

    @robmadole
    Member

    @mhoeher I'm not sure I can be of much use to you. Those fonts are using different weight classes. I'm not sure how Qt handles that. You might try using the .OTF files instead if that's possible.

  4. mhoeher commented on Apr 10, 2018

    @mhoeher
    Author

    Hi @robmadole,

    I modified my sample from above and replaced the *.ttf fonts with the *.otf ones, however, the result is the same. :-(

  5. huyder commented on Jul 25, 2018

    @huyder

    One of our application we are using is using the qt QFontDatabase (https://doc.qt.io/qt-5/qfontdatabase.html#addApplicationFont) class and we are having a similar problem with it not being able to distinguish between the light/regular/solid TTF webfonts. The developer of that software company informed us that the cause of the issue is because all these TTF fonts have the exact same name: "Font Awesome 5 Pro".

    Can you please add "Light", "Regular", and "Solid" to the name of these fonts so that libraries like Qt can distinguish them?

  6. tagliala commented on Jul 25, 2018

    @tagliala
    Member

    Maybe this is the same issue as #13320

  7. mhoeher commented on Jul 29, 2018

    @mhoeher
    Author

    Hi @tagliala,

    after your hint I tried my example from above with the most recent release. The good news: Using the *.otf font files from the desktop release package, I now get the expected result:

    image

    So it seems there were some fixes for these files :-)

    In addition, I tried with the .ttf fonts from the web fonts zip, but using these, I still get the wrong output shown in my earlier post.

  8. tagliala commented on Jul 29, 2018

    @tagliala
    Member

    Glad you've solved.

    .ttf files are not supposed to be used on the desktop, because they are generated for the web by a webfont script

  9. mhoeher commented on Jul 29, 2018

    @mhoeher
    Author

    Okay, then I think this issue can be considered done ;-)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions