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?
Forum Updated to NodeBB v4.3 + New Features

Read font name from file?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 2 Posters 793 Views 1 Watching
  • 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 20 Aug 2019, 07:55 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
    • M Offline
      M Offline
      mrjj
      Lifetime Qt Champion
      wrote on 20 Aug 2019, 17:26 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 21 Aug 2019, 05:47 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.

        M 1 Reply Last reply 21 Aug 2019, 06:12
        0
        • E Elsworth55
          21 Aug 2019, 05:47

          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.

          M Offline
          M Offline
          mrjj
          Lifetime Qt Champion
          wrote on 21 Aug 2019, 06:12 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 21 Aug 2019, 13:46
          1
          • M mrjj
            21 Aug 2019, 06:12

            @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 21 Aug 2019, 13:46 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

            1/5

            20 Aug 2019, 07:55

            • Login

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