[Qt-interest] Using multiple line endings with QPlainTextEdit

Adam Light aclight at gmail.com
Wed Sep 7 01:26:05 CEST 2011


I have a widget in my application that is derived from QPlainTextEdit.
The text string that is displayed in this widget could have any or all
of CR, LF, or CRLF as line endings, and I want these line endings to
be preserved. Is there a straightforward way to do this? From what I
have found so far, QPlainTextEdit::setText() ends up calling
QTextCursor::insertText(), which strips out all line endings and
instead creates new blocks for each "paragraph". When
QPlainTextEdit::toPlainText() is later called, the blocks are joined
together with LF characters.

I have been able to work around this to some extent by creating
wrapper functions for setText() and toPlainText() that store the line
ending each block uses in the block's userState property. However, I'm
having trouble getting the correct behavior for drag and drop,
copy/paste, and undo/redo.

Any suggestions?

Thanks
Adam Light



More information about the Qt-interest-old mailing list