Results 1 to 2 of 2

Thread: QTextEdit undo/redo

  1. #1
    Join Date
    Mar 2006
    Posts
    3
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X

    Default QTextEdit undo/redo

    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

  2. #2
    Join Date
    Jul 2009
    Posts
    42
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QTextEdit undo/redo

    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:


    Qt Code:
    1. ...
    2. documentCursor->beginEditBlock();
    3. do{
    4. documentCursor->insertText(QString("%1: ")
    5. .arg(documentCursor->blockNumber()+1,7,10,QChar(' ')));
    6.  
    7. }while(documentCursor->movePosition(QTextCursor::NextBlock));
    8.  
    9. documentCursor->endEditBlock();
    10. }
    11.  
    12. document->print(&printer);
    13.  
    14. if (printLineNumbers) document->undo();
    15. ...
    To copy to clipboard, switch view to plain text mode 

    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

Similar Threads

  1. Re-implement mouse events of QTextEdit
    By Ankitha Varsha in forum Qt Programming
    Replies: 2
    Last Post: 14th October 2006, 16:55
  2. QTextEdit API questions (plain text)
    By Gaspar in forum Qt Programming
    Replies: 4
    Last Post: 16th May 2006, 06:03
  3. [QT 4] QTextEdit performance
    By fellobo in forum Qt Programming
    Replies: 8
    Last Post: 6th March 2006, 19:27
  4. Painting to QTextEdit
    By gesslar in forum Qt Programming
    Replies: 8
    Last Post: 18th February 2006, 18:40
  5. Obtaining clean (x)html from QTextEdit
    By ccf_h in forum Qt Programming
    Replies: 1
    Last Post: 5th February 2006, 14:47

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.