pythonpyqt4qfont

Returning fontsize and font family from QFontDialog PyQt


Is there a way to return the font size and font name from QFontDialog? I'm new on python and all the examples I have seen do not return the font name and/or font size.

What I have now it's something like this:

def font_picker(self, button, line):
  font, ok = QtGui.QFontDialog.getFont()

  if ok:
     button.setFont(font)
     line.setFont(font)

But I don't know how to return fontsize as a float and fontfamily as a string


Solution

  • The QFont object itself has pixelSize, pointSize and pointSizeF for getting the size. It has family for getting the font family.

     if ok:
         button.setFont(font)
         line.setFont(font)
         return font.pointSizeF(), font.family()