开发者

Qt, QTextEdit: how do I delete the last character?

开发者 https://www.devze.com 2023-01-03 16:50 出处:网络
I am using a QTextEdit in my C++ GUI application, I use textEdit->append(byteArray); to add some text, unfortunately append() adds a new line character at the end that I would like to re开发者_StackOv

I am using a QTextEdit in my C++ GUI application, I use textEdit->append(byteArray); to add some text, unfortunately append() adds a new line character at the end that I would like to re开发者_StackOverflow中文版move after each call of append(). I know I could use insertPlainText() which does not add a new line character but it uses a lot more memory when dealing with big documents.

Thanks for your help!


Since the documentation for QTextEdit::insertPlainText says

It is equivalent to

edit->textCursor().insertText(text);

I would assume that you can just do something like

edit->textCursor().deletePreviousChar();

If you need to you can first clear any selection with

edit->textCursor().clearSelection();
0

精彩评论

暂无评论...
验证码 换一张
取 消