How to determine ascender and descender heights of QGraphicsTextItem and QFont?
-
I create QGraphicsTextItem with QGraphicsScene::addText(const QString&, const QFont&).
QGraphicsTextItem::boundingRect() gives me the bounding box of the text. I assume this box is the box enclosing ascender and descender space.I need to draw the subscript near the text.
In order to do this properly, I need to know ascender and descender heights, and find the text baseline.
How can I know the baseline of the resulting text if there are no methods in API giving me descender height?I think, in perfect world, QGraphicsTextItem should be able to return the real ascender and descender heights of the text. Also, QFont should be able to return the same for the font.
-
You could see this "QFontMetrics":http://qt-project.org/doc/qt-4.8/qfontmetrics.html
-
You want to be careful, though. You said QGraphicsTextItem should be able to return the "real ascender and descender heights of the text." First of all, ascender and descender are only guides according to the TrueType and OpenType specifications. Second, I'm not sure how your implementation plans to use them. Consider the fact that g may descend lower than p (or not) and that M may ascend higher than t.