[SOLVED] QtextEdit/QTextDocument undo of setPlainText ?
-
Hi all,
I have a QTextEdit object with some text inside. I have a function that "beautifies" (indents) the text doing a whole replacement of the underlying text (using myTextEdit->document()-> setPlainText( ... ) method).My problem is that undo is not available for that action. How could I solve that ?
MaX.
-
Check "this":http://doc.qt.io/qt-5/qundo.html page out. You need to use the undo framework when programmatically editing the text. Otherwise Qt cannot know how to undo it.
-
Hi,
Isn't "QTextDocument::undo()":http://doc.qt.io/qt-5/qtextdocument.html#undo-2 what you are looking for ?
-
[quote author="SGaist" date="1422218961"]Hi,
Isn't "QTextDocument::undo()":http://doc.qt.io/qt-5/qtextdocument.html#undo-2 what you are looking for ?[/quote]
Hmm no, because when I do (programmatically) a myTextEdit->document()-> setPlainText( … ), the undo stack of the TextEdit is cleared (that's stated in the doc), same if I do a myTextEdit->setPlainText( … ).
Hence after I set the beautified text, there's no available undo action in the QTextEdit.
MaX.
-
The documentation of the function doesn't mention that (it will be corrected in a future version) But indeed, the undo stack is also cleared. So the only technique I see so far would be to select all the text programmatically, delete it and then use append to insert your new text (I haven't tested it though)
-
[quote author="SGaist" date="1422226268"]So the only technique I see so far would be to select all the text programmatically, delete it and then use append to insert your new text (I haven't tested it though)[/quote]
That worked like a charm ! Thanks !
MaX.