question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

High chance of font family conflicts with bundled fonts

See original GitHub issue

Hi,

For some fonts that qtawesome has, family remains the default. This may break the user application or qtawesome if the user adds a different version of the font.

For example, in the following code, if the different version of “Material Design Icon” by QtGui.QFontDatabase.addApplicationFont("materialdesignicons-webfont.ttf") is added, qtawesome icon disappers.

QtGui.QFontDatabase.addApplicationFont affects application-wide, so qtawesome’s internal “Materinal Design Icon” seems to be overwritten by user’s one.

I think it’s a good idea to add a unique string (e.g “(qtawesome)”) to all families of qtawesome’s internal icons to avoid the confliction.


# -*- coding: utf-8 -*-
import sys
from qtpy import QtCore, QtWidgets, QtGui
import qtawesome as qta

class AwesomeExample(QtWidgets.QDialog):

    def __init__(self):
        super().__init__()

        # Get Material Design icons by name
        mdi6_icon = qta.icon('mdi6.account-wrench')
        mdi6_button = QtWidgets.QPushButton(mdi6_icon, 'Material Design Icon # Version 6.3.95, ch=F189A')

        #
        # Add different version of 'Material Design Icon' from qtawesome's internal
        # For example, if version 6.2.95 is added, mdi6.account-wrench (ch=F1809A) disappers
        #
        QtGui.QFontDatabase.addApplicationFont("materialdesignicons-webfont.ttf")

        font = QtGui.QFont("Material Design Icon")
        fontMetrics = QtGui.QFontMetrics(font)
        print(f"font.key()                      : {font.key()}")
        print(f"fontMetrics.inFontUcs4(0xF189A) : {fontMetrics.inFontUcs4(0xF189A)}")

        grid = QtWidgets.QGridLayout()
        grid.addWidget(mdi6_button, 0, 0)
        self.setLayout(grid)
        self.setWindowTitle('Awesome')
        self.show()


def main():
    app = QtWidgets.QApplication(sys.argv)
    if hasattr(QtCore.Qt, 'AA_UseHighDpiPixmaps'):
        app.setAttribute(QtCore.Qt.AA_UseHighDpiPixmaps)
    QtCore.QTimer.singleShot(10000, app.exit)
    _ = AwesomeExample()
    sys.exit(app.exec_())


if __name__ == '__main__':
    main()
  • QtGui.QFontDatabase.addApplicationFont("materialdesignicons-webfont.ttf") is not executed Screenshot from 2021-12-02 00-37-48

  • QtGui.QFontDatabase.addApplicationFont("materialdesignicons-webfont.ttf") is executed Screenshot from 2021-12-02 00-36-12

Issue Analytics

  • State:open
  • Created 2 years ago
  • Comments:12 (12 by maintainers)

github_iconTop GitHub Comments

3reactions
kumattaucommented, Dec 2, 2021

Ok, great! Could you give us a hand with that?

Yes, I will try it soon.

2reactions
ccordoba12commented, Dec 6, 2021

Just in case, what do you think @ccordoba12 ?

I think it’s fine as long as updating to new font versions remains easy.

Read more comments on GitHub >

github_iconTop Results From Across the Web

How to avoid layout shifts caused by web fonts - Simon Hearne
One of the biggest causes of layout shifts for my clients is late-loading web fonts, let's look at how to optimise them!
Read more >
A New Way To Reduce Font Loading Impact: CSS Font ...
Web fonts are often terrible for web performance and none of the font loading strategies are particularly effective to address that.
Read more >
How to Load Fonts in a Way That Fights FOUT and Makes ...
Choose a few nice-looking web-ready fonts, get the HTML or CSS code ... Not great. ... The risk of losing a font isn't...
Read more >
The dispute about sans serif versus serif fonts: An interaction ...
It is a long-lasting dispute whether serif or sans serif fonts are more legible. ... The font family of Lucida: Lucida (top) and...
Read more >
CSS Fonts Module Level 4 - W3C
“At-risk” is a W3C Process term-of-art, and does not necessarily ... 4.9.1 Controlling Font Display Per Font-Family via @font-feature-values.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found