Implementing the undo function (e.g. Ctrl + Z) in Qt / C ++

I use Qt 4.5also C++in Windows XP.

Basically I will have a user interface in which the user enters some data. It can change and change the values ​​available in the user interface. The user interface will contain basic Qt interface elements, such as QLineEdit, QTableWidgetetc.,

So, if the user presses the button Undo(or Ctrl+Z), the previous value should be stored in the corresponding user interface element.

Say, if there is text QLineEditwith the text 25. Now the user changes the value 30. Now, by clicking "Cancel", you need to save the older value 25.

Like the undo feature, which is commonly available in many applications. Is there any way to do this?

+3
source share
4 answers

You can use Qt undo framework .

+7
source

A typical way to implement Undo is to present each action performed by the user and save it. You also need the ability to calculate the opposite for a given action.

So, to insert into the text buffer, the action will save the entered text and the place where the insert is inserted. The converse then becomes deletion at the same location and with the size of the inserted text.

, . , "" , , Redo, .

, ; , Qt Undo, , , .

+5
+2

Source: https://habr.com/ru/post/1775600/


All Articles