QFontMetrics should be retrieved by QPainter.fontMetrics(), or width measurement will be inaccurate.