QFont font("Times", 12, QFont::Bold); QPainter painter(this); painter.setFont(font); QFontMetrics fm(painter.font()); int textWidth = fm.width("Hello world");
int fontHeight = painter.fontMetrics().height();In this example, we retrieve the height of the font currently set in the QPainter object using the height() method. Package library: Qt Core module.