from PyQt4 import QtGui # create a font object font = QtGui.QFont("Helvetica", 12) # create a QFontMetricsF object for the font above font_metrics = QtGui.QFontMetricsF(font) # get the width of a string using the QFontMetricsF object width = font_metrics.width("Hello World") print(width)
from PyQt4 import QtGui # create a font object font = QtGui.QFont("Times New Roman", 14) # create a QFontMetricsF object for the font above font_metrics = QtGui.QFontMetricsF(font) # get the height of a string using the QFontMetricsF object height = font_metrics.height() print(height)This example creates a font object with the 'Times New Roman' font and a size of 14. A QFontMetricsF object is created for this font object which is then used to obtain the height of the font. The height is then printed to the console.