I need to append text to QPlainTextEdit without adding a newline to the text, but both methods appendPlainText() and appendHtml() adds actually new paragraph.
I can do that manually with QTextCursor:
QTextCursor text_cursor = QTextCursor(my_plain_text_edit->document());
text_cursor.movePosition(QTextCursor::End);
text_cursor.insertText("string to append. ");
That works, but I also need to keep scroll at bottom if it was at bottom before append.
I tried to copy logic from Qt’s sources, but I stuck on it, because there actually QPlainTextEditPrivate class is used, and I can’t find the way to do the same without it: say, I don’t see method verticalOffset() in QPlainTextEdit.
Actually, these sources contain many weird (at the first look, at least) things, and I have no idea how to implement this.
Here’s the source code of append(): http://code.qt.io/cgit/qt/qt.git/tree/src/gui/widgets/qplaintextedit.cpp#n2763
Ok, I’m not sure if my solution is actually “nice”, but it seems to work for me: I just made new class
QPlainTextEdit_Myinherited fromQPlainTextEdit, and added new methodsappendPlainTextNoNL(),appendHtmlNoNL(),insertNL().Please NOTE: read comments about params
check_nlandcheck_brcarefully, this is important! I spent several hours to figure out why is my widget so slow when I append text without new paragraphs.I’m confused because in original code there are much more complicated calculations of
atBottom:and
needScroll:But my easy solution seems to work too.