Search code examples
c++qt4qt5

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?


Solution

  • 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.