PDA

View Full Version : QTextEdit undo/redo



Derf
3rd November 2006, 14:36
Hello
I use Qt 4.2.0 on a mac.

Does a QTextEdit::setDocument() destroy the document's undo stack ?

I am trying to implement undo/redo (with a QUndoStack) for an outliner-like application.
The user can select a row in a tree view, and an associated document appears in a text edit. I use setDocument to switch between documents.

The undo/redo works for the current document's changes, but after a document switch the text edit says no undo avaiable. Hence my question.

--

A related question : Is there a way to set the textEdit or documents undoStack to my undoStack ? I wanted to make undo macros with some textEdit manipulations and had to create my undo commands, only to do something like textEdit->undo() in it. Seems strange. What did I fail to understand ?

--

Third question : when the textEdit has the focus, a shortcut-triggered undo does an undo in the textEdit, but not in my stack which lies in the mainWindow. Do I have to make a filter to catch the undo event in my mainWindow, or is there a way to tell a textEdit something like "forget the undo and redo shortcuts" ?

Thanks in advance for your answers.
Derf

ericV
6th August 2009, 09:12
I realise that this thread is fairly old, but i have ran into a similar problem using QT 4.5 on Windows.

I have a TextEdit with Textdocument, and when i print the document i programmatically append the line number in front of each block, like so:



...
documentCursor->beginEditBlock();
do{
documentCursor->insertText(QString("%1: ")
.arg(documentCursor->blockNumber()+1,7,10,QChar(' ')));

}while(documentCursor->movePosition(QTextCursor::NextBlock));

documentCursor->endEditBlock();
}

document->print(&printer);

if (printLineNumbers) document->undo();
...

now i would like to remove the last redo from the undo-stack, but i cant find a way to do this.

I know that it is possible to implement a custom Undo Stack... but i feel that this is not worth it just for this function.

Anyone have any ideas how i can clear the one redo command? I could trick it by adding a space or something at the end of the document and then undo that... but this isn't very elegant, since there would still be a redo option every time the user hits print.

Maybe something like pausing the undo redo for the document temporarily... but i haven't found anything like that....

Thanks

Eric