Results 1 to 6 of 6

Thread: Setting Text in QPlainTextEdit without Clearing Undo/Redo History

  1. #1
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Question Setting Text in QPlainTextEdit without Clearing Undo/Redo History

    Hello.
    How can I set text in QPlainTextEdit without clearing the undo/redo history?

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting Text in QPlainTextEdit without Clearing Undo/Redo History

    You can try
    1. access to the document
    2. create a text cursor
    3. select all text in the document
    4. delete selected text
    5. insert new text


    Qt Code:
    1. QTextDocument *doc = plainTextEdit->document();
    2.  
    3. QTextCursor curs (doc);
    4.  
    5. curs.select (QTextCursor::Document);
    6.  
    7. curs.removeSelectedText ();
    8.  
    9. curs.insertText (newText);
    To copy to clipboard, switch view to plain text mode 
    A camel can go 14 days without drink,
    I can't!!!

  3. The following user says thank you to mcosta for this useful post:

    Furkan (20th July 2011)

  4. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: Setting Text in QPlainTextEdit without Clearing Undo/Redo History

    I haven't tried it, but maybe using QCursor directly wont clear the history.


    ...too late.

  5. #4
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Setting Text in QPlainTextEdit without Clearing Undo/Redo History

    Thank you so much. It works. But it also takes the empty document (When you remove selected text) into the undo/redo history.

  6. #5
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Setting Text in QPlainTextEdit without Clearing Undo/Redo History

    delete the line
    Qt Code:
    1. curs.removeSelectedText ();
    To copy to clipboard, switch view to plain text mode 

    from my code
    Last edited by mcosta; 20th July 2011 at 15:23. Reason: updated contents
    A camel can go 14 days without drink,
    I can't!!!

  7. #6
    Join Date
    Apr 2010
    Posts
    31
    Thanks
    1
    Qt products
    Qt4 Qt/Embedded
    Platforms
    Unix/X11 Windows Symbian S60

    Default Re: Setting Text in QPlainTextEdit without Clearing Undo/Redo History

    How could I not think about that!?
    Thank you so much. It works perfect now!

Similar Threads

  1. undo/redo example has refactored
    By n_vova in forum Qt Programming
    Replies: 1
    Last Post: 10th May 2012, 10:04
  2. Undo/Redo issues of QTextEdit
    By Maximka in forum Newbie
    Replies: 0
    Last Post: 22nd February 2010, 07:36
  3. QTextEdit undo/redo
    By Derf in forum Qt Programming
    Replies: 1
    Last Post: 6th August 2009, 09:12
  4. Detecting a action ( undo/ redo)
    By ankurjain in forum Qt Programming
    Replies: 2
    Last Post: 5th May 2006, 05:05
  5. Implement Undo Redo
    By ankurjain in forum Qt Programming
    Replies: 5
    Last Post: 28th March 2006, 13:17

Tags for this Thread

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.