PDA

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



zack
14th July 2010, 13:06
Hello!

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?

Lykurg
14th July 2010, 13: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.