How to get the font size (in pxl) of a text with paragraphs?
Unsolved
General and Desktop
-
-
Hi! In my experience this is a very tricky thing. If your intention is to draw the text with QPainter, I'd recommend to drop QFontMetrics and instead render the text to an "offscreen" image first to get the bounding rect. Something like:
static QRectF getBoundingBox(QString const &s, QFont const &f) { QImage image(1, 1, QImage::Format_Mono); QPainter painter(&image); painter.setFont(f); QRectF rr; painter.drawText(QRectF(0, 0, INT_MAX, INT_MAX), Qt::TextWordWrap, s, &rr); return rr; }