Hi,
I have QtEmbedded 4.4.1. I am trying to draw text within a rectangle (as per the picture), however, there is too much spacing between the lines. I know this is probably related to the QFontMetrics::lineSpacing().
I have a button rectangle, and a text rectangle, I am drawing the text rectangle inside the button rectangle. The text rectangle coordinates are relative to the button coordinates, not the screen coordinates, that is why I have to draw an adjusted button rectangle.
Anyways, this works, but the font display spacing is too large, and I must also consider different translations ( accents on the chars, etc).
image.png is actual
spec.png is required
qDebug() << fm.lineSpacing() << fm.leading() << fm.height();
QRectF adjRect
(rect
().
adjusted(txtRect.
x(),txtRect.
y(),
-txtRect.x(), -(rect().bottom() - (rect().y()+txtRect.y()+txtRect.height()))));
painter->drawText(adjRect,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
painter->drawRect(adjRect); // for debugging
QFontMetrics fm(txtFont);
qDebug() << fm.lineSpacing() << fm.leading() << fm.height();
QRectF adjRect(rect().adjusted(txtRect.x(),txtRect.y(),
-txtRect.x(), -(rect().bottom() - (rect().y()+txtRect.y()+txtRect.height()))));
painter->drawText(adjRect,Qt::AlignCenter|Qt::TextWordWrap,messageLabel);
painter->drawRect(adjRect); // for debugging
To copy to clipboard, switch view to plain text mode
1) Can I reduce the line spacing? (I would like to increase the font size)
2) Is this the best method to draw text taking into consideration other languages? I worry that the top line will cut-off accents.
Bookmarks