Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] QtextEdit/QTextDocument undo of setPlainText ?

[SOLVED] QtextEdit/QTextDocument undo of setPlainText ?

Scheduled Pinned Locked Moved General and Desktop
7 Posts 3 Posters 3.1k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • H Offline
    H Offline
    HornetMaX
    wrote on last edited by
    #1

    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.

    1 Reply Last reply
    0
    • C Offline
      C Offline
      ckakman
      wrote on last edited by
      #2

      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.

      1 Reply Last reply
      0
      • H Offline
        H Offline
        HornetMaX
        wrote on last edited by
        #3

        Thanks. I did stumble on that page before posting, but I'm a bit lost: how do I get the stack associated to the document ?

        MaX.

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          Hi,

          Isn't "QTextDocument::undo()":http://doc.qt.io/qt-5/qtextdocument.html#undo-2 what you are looking for ?

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • H Offline
            H Offline
            HornetMaX
            wrote on last edited by
            #5

            [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.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              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)

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • H Offline
                H Offline
                HornetMaX
                wrote on last edited by
                #7

                [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.

                1 Reply Last reply
                0

                • Login

                • Login or register to search.
                • First post
                  Last post
                0
                • Categories
                • Recent
                • Tags
                • Popular
                • Users
                • Groups
                • Search
                • Get Qt Extensions
                • Unsolved