Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Read font name from file?

Read font name from file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 773 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.
  • E Offline
    E Offline
    Elsworth55
    wrote on last edited by
    #1

    Is there any way to read the font name from a font file?

    I tried the below solution, but this only returns the font family so if the font is Arial Bold it will only return Arial.

        int id = QFontDatabase::addApplicationFont(filePath);
        if (id != -1)
        {
            QStringList fontFamily = QFontDatabase::applicationFontFamilies(id);
            QFontDatabase::removeApplicationFont(id);
        }
    

    Is there any way to get the full font name?

    1 Reply Last reply
    0
    • mrjjM Offline
      mrjjM Offline
      mrjj
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi
      I could not see any public access.

      The path is stored in private class
      https://code.woboq.org/qt5/qtbase/src/gui/text/qfontdatabase.cpp.html#QFontDatabasePrivate
      in the struct

      struct ApplicationFont {
              QString fileName;
              QByteArray data;
              QStringList families;
          };
      

      I did look around to see if it was surfaced but to no avail.

      1 Reply Last reply
      1
      • E Offline
        E Offline
        Elsworth55
        wrote on last edited by
        #3

        Thanks a lot for looking. It looks like there might not be an easy solution in Qt.

        I'll have a look if there's a cross platform library that can read the full name.

        mrjjM 1 Reply Last reply
        0
        • E Elsworth55

          Thanks a lot for looking. It looks like there might not be an easy solution in Qt.

          I'll have a look if there's a cross platform library that can read the full name.

          mrjjM Offline
          mrjjM Offline
          mrjj
          Lifetime Qt Champion
          wrote on last edited by
          #4

          @elsworth55

          Hi
          Looking around i tripped over this
          https://www.qtcentre.org/threads/26924-Retrieve-the-filename-of-a-QFont

          but its windows bound.

          E 1 Reply Last reply
          1
          • mrjjM mrjj

            @elsworth55

            Hi
            Looking around i tripped over this
            https://www.qtcentre.org/threads/26924-Retrieve-the-filename-of-a-QFont

            but its windows bound.

            E Offline
            E Offline
            Elsworth55
            wrote on last edited by
            #5

            @mrjj Thanks a lot for looking, but unfortunately the application is for Windows, Mac and Linux so the solution would have to be cross-platform.

            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