QFont font("Arial", 12); QFontMetrics metrics(font); int height = metrics.height(); // returns the pixel height of the font
QString text = "Hello, world!"; int textWidth = metrics.width(text); // returns the pixel width of the textIn this example, we create a QString object containing the text "Hello, world!". We then call the width() method of the QFontMetrics object, passing in the text as an argument, to get the pixel width of the text. Based on these code examples, it is likely that QFontMetrics is part of the Qt library.