Implementing Undo - Redo Functionality in Qt?

后端 未结 3 1184
无人及你
无人及你 2021-02-08 18:35

My program consists of multiple QLineEdit\'s in my QMainWindow. The user can change the text in any QLineEdit. Currently I can perform

3条回答
  •  孤街浪徒
    2021-02-08 19:17

    Qt provides an Undo/Redo framework.

    You basically implement a command, derived from QUndoCommand, for each of the actions you want to make undoable/redoable, and then push them to a QUndoStack. Later, the commands can be undone and redone by calling the corresponding slots on the QUndoStack.

    Note that, when pushing a command on the stack, it is automatically redone, means executed for the first time. Sometimes this is not what you want, since the command might actually already have been executed - you would need to consider this in the implementation of your commands.

提交回复
热议问题