piotrekg2 piotrekg2 - 1 month ago 10
C++ Question

QTextLayout manual line breaking

I'm trying to render lines one by one using

QTextLayout
. I've tried to set
wrapMode
to
QTextOption::ManualWrap
and call
QTextLine::setNumColumns
for each line but the whole text appears in a single line.

I've also tried to set
wrapMode
to
QTextOption::WrapAnywhere
and this time the text is broken into lines but the empty lines (the ones which consist only of
\n
) are not visible.

I've tried to link against both
Qt4
and
Qt5
with no results.

What am I doing wrong?

Answer

It turns out that Qt implements this by creating a new QTextLayout for each line. The details can be found in QPlainTextEdit::paintEvent(QPaintEvent *) source.