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

Get the style of the font file using QFont

Scheduled Pinned Locked Moved General and Desktop
qfontpython
6 Posts 2 Posters 2.3k Views 2 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.
  • G Offline
    G Offline
    Gowthaman
    wrote on 21 May 2015, 19:58 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
    • S Offline
      S Offline
      SGaist
      Lifetime Qt Champion
      wrote on 21 May 2015, 20:42 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 21 May 2015, 20:57 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
        • S Offline
          S Offline
          SGaist
          Lifetime Qt Champion
          wrote on 21 May 2015, 21:01 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 22 May 2015, 00:08 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
            • S Offline
              S Offline
              SGaist
              Lifetime Qt Champion
              wrote on 22 May 2015, 20:41 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

              4/6

              21 May 2015, 21:01

              • Login

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