user49685
user49685

Reputation: 151

How to get the height from the top of character to its base line (i.e, its actual ascent) in QWidget?

I am experimenting to build a tool that can display modified text (i.e, with some additional stroke) on screen using QWidget. So, to put the stroke in its correct position, I need to know the ascent height of the character the stroke is being put on.

And I'm a tad stuck on retrieving the actual ascent of a character. I have tried some of the following things:

How do I solve this problem?

Upvotes: 2

Views: 235

Answers (1)

G.M.
G.M.

Reputation: 12879

You can use QFontMetrics::boundingRect. The QRect returned will have its origin at (0, 0) with the ascent for character c represented by...

-QFontMetrics::boundingRect(c).top()

and, similarly, the descent by...

QFontMetrics::boundingRect(c).bottom()

Upvotes: 3

Related Questions