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. Get QFont type issue
Qt 6.11 is out! See what's new in the release blog

Get QFont type issue

Scheduled Pinned Locked Moved Solved General and Desktop
2 Posts 1 Posters 289 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.
  • Cobra91151C Offline
    Cobra91151C Offline
    Cobra91151
    wrote on last edited by
    #1

    Hello!

    I want to extract the font type information from a file. For example, I have 2 font files: .ttf and .otf.
    How to get the OpenType or TrueType font type using Qt API? Is there any QFont methods to get such information? Thank you.

    1 Reply Last reply
    0
    • Cobra91151C Offline
      Cobra91151C Offline
      Cobra91151
      wrote on last edited by Cobra91151
      #2

      Ok. I have got the font type information by font file mime type. Here is my solution.

      Code:

      QString getFontType(const QString &fileName) 
      {
         QString fontType = "";
         QMimeDatabase mimeDB;
         QMimeType mimeType = mimeDB.mimeTypeForFile(fileName, QMimeDatabase::MatchContent);
      
         if (mimeType.name().contains("application/x-font-ttf")) {
             fontType = "TrueType";
         } else if (mimeType.name().contains("application/x-font-otf")) {
             fontType = "OpenType";
         } else {
             fontType = "OtherType";
         }
      
         return fontType;
      }
      

      So, the issue is resolved.

      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