Get the style of the font file using QFont
-
wrote on 21 May 2015, 19:58 last edited by
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?
-
Hi and welcome to devnet,
Do you mean QFont::styleName ?
-
wrote on 21 May 2015, 20:57 last edited by
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?
-
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
-
wrote on 22 May 2015, 00:08 last edited by
Weight command is also not working. I'm always getting this as output no matter what the font is
QtGui.QFont.Weight(0)
-
Weight is an enumeration and theres a corresponding getter
3/6