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 the style of the font file using QFont
QtWS25 Last Chance

Get the style of the font file using QFont

Scheduled Pinned Locked Moved General and Desktop
qfontpython
6 Posts 2 Posters 2.2k 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.
  • G Offline
    G Offline
    Gowthaman
    wrote on last edited by
    #1

    Is there a command in QFont where I can get the style of the font. I figured out how to get the family name of the font file but not the specific style of the file. I found a command which returns the entire list of styles associated with the font family.

    styleList = QtGui.QFontDatabase.styles(fontFamilyName)
    

    I need the exact style of the specific font file. For example, if I give arialb.ttf as an input, I should be getting family name: Arial; style: Bold. Any ideas?

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

      Hi and welcome to devnet,

      Do you mean QFont::styleName ?

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • G Offline
        G Offline
        Gowthaman
        wrote on last edited by
        #3

        Hello Gaist,

        Thanks for the quick response! I tried this but I am getting empty string. This is my code

               fontFile = "C:\Users\Desktop\abc.otf"
               fontdb = QtGui.QFontDatabase()
               id = fontdb.addApplicationFont(fontFile)
               family = fontdb.applicationFontFamiles(id)
               font = QtGui.QFont(family[0])
               print font.styleName()
        

        What am I doing wrong?

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by SGaist
          #4

          So it seems you're using the one desktop OS that isn't supported by this method

          However, depending on what information you are looking for, Weight might be an option

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • G Offline
            G Offline
            Gowthaman
            wrote on last edited by
            #5

            Weight command is also not working. I'm always getting this as output no matter what the font is

                 QtGui.QFont.Weight(0)
            
            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Weight is an enumeration and theres a corresponding getter

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              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