Thanks for the tip,
I created a widget with the TextLayout and it works fine, but I noticed that newline are ignored by QtextLayout, so if I do:
textLayout.setText("Test \n \n Hello");
int leading = fontMetrics.leading();
int height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
if (!line.isValid())
break;
line.setLineWidth(width());
height += leading;
line.
setPosition(QPoint(0, height
));
height += line.height()+space;
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout.endLayout();
QFontMetrics fontMetrics(QApplication::font());
textLayout.setText("Test \n \n Hello");
int leading = fontMetrics.leading();
int height = 0;
qreal widthUsed = 0;
textLayout.beginLayout();
while (1) {
QTextLine line = textLayout.createLine();
if (!line.isValid())
break;
line.setLineWidth(width());
height += leading;
line.setPosition(QPoint(0, height));
height += line.height()+space;
widthUsed = qMax(widthUsed, line.naturalTextWidth());
}
textLayout.endLayout();
To copy to clipboard, switch view to plain text mode
when drawing there's no white lines between Test and Hello but they're both written on the same line,
is there a way to make Qtetxlayout consider \n ?
thanks
Bye
Bookmarks