View Full Version : get exact height of a QString in pixels

14th July 2010, 14:06

How can I get the height of a QString in pixels?
Using QFontMetric doesn't seam to work.

I print an "x" and I get via QFontMetric ::size a height of 14, but where the character is only 6 pixels height.
why is there a 'height()' function in QFontMetric without QString argument, every character has a different height.

Any suggestions?

14th July 2010, 14:16
It only returns the height of the used font. The string parameter is useful if you have line breaks in it.

To measure the actual height I can only thing of that nasty solution: Paint the string to a white pixmap and count all lines which only have white pixels. so you can get the absolute height of your character.