Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Qt for Python
  4. Unsuccessfully adding new font in pyqt5
Forum Update on Monday, May 27th 2025

Unsuccessfully adding new font in pyqt5

Scheduled Pinned Locked Moved Unsolved Qt for Python
3 Posts 3 Posters 672 Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    sLawalata
    wrote on last edited by
    #1

    greetings,

    I try to add new font in my pyqt5 apps with this code:

    I am sure that it has correct file path points to right files. It can load it and add to font_db by succesfully printing font family.

    font_db = QtGui.QFontDatabase()
    
       for f in ['resources/fonts/GothamNarrowBold.otf', 'resources/fonts/GothamNarrowBook.otf']:
           font_files = os.path.join(package_dir, f)
           print(font_files)
           font_id = font_db.addApplicationFont(font_files)
           font_family = font_db.applicationFontFamilies(font_id)
           print(font_family)
    

    but I still get this error message.

    qt.qpa.fonts: Populating font family aliases took 103 ms. Replace uses of missing font family "Gotham Narrow Bold" with one that exists to avoid this cost.
    

    What I have missed? Somebody can help me to solve this problem?

    thanks in advance.

    same question posted here.

    1 Reply Last reply
    0
    • CristianMaureiraC Offline
      CristianMaureiraC Offline
      CristianMaureira
      wrote on last edited by
      #2

      Are you placing your fonts on a .qrc as well, or you are only using the relative path?

      JonBJ 1 Reply Last reply
      0
      • CristianMaureiraC CristianMaureira

        Are you placing your fonts on a .qrc as well, or you are only using the relative path?

        JonBJ Offline
        JonBJ Offline
        JonB
        wrote on last edited by JonB
        #3

        @CristianMaureira said in Unsuccessfully adding new font in pyqt5:

        only using the relative path?

        Depending what you mean by "relative", note that the OP makes the paths absolute with font_files = os.path.join(package_dir, f). So assuming he has checked in there for the presence of the files.

        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved