PDA

View Full Version : Setting Text in QPlainTextEdit without Clearing Undo/Redo History



Furkan
20th July 2011, 14:32
Hello.
How can I set text in QPlainTextEdit without clearing the undo/redo history?

mcosta
20th July 2011, 14:56
You can try

access to the document
create a text cursor
select all text in the document
delete selected text
insert new text




QTextDocument *doc = plainTextEdit->document();

QTextCursor curs (doc);

curs.select (QTextCursor::Document);

curs.removeSelectedText ();

curs.insertText (newText);

Lykurg
20th July 2011, 14:56
I haven't tried it, but maybe using QCursor directly wont clear the history.


...too late.

Furkan
20th July 2011, 16:01
Thank you so much. It works. But it also takes the empty document (When you remove selected text) into the undo/redo history.

mcosta
20th July 2011, 16:23
delete the line

curs.removeSelectedText ();

from my code

Furkan
20th July 2011, 21:01
How could I not think about that!?
Thank you so much. It works perfect now!