Undo/Redo in PyQt

Z

Zabin

Hey!

I am trying to implement the undo and redo facility in pyqt. I have
gone through some sites and was wondering whether iyou always need to
create subclasses and their definitions for the undo/redo action. My
program currently has a single window in which the user enters
information which is used to update a text file as soon as the user
leaves the field- so i essentially need to undo the text in that field
as well as the file. I am puzzled as to how to approach this. Any help
will be much appreciated!

Cheers
Zabin
 
D

David Boddie

I am trying to implement the undo and redo facility in pyqt. I have
gone through some sites and was wondering whether iyou always need to
create subclasses and their definitions for the undo/redo action. My
program currently has a single window in which the user enters
information which is used to update a text file as soon as the user
leaves the field- so i essentially need to undo the text in that field
as well as the file. I am puzzled as to how to approach this. Any help
will be much appreciated!

From memory and a quick glance at the documentation for QUndoCommand, I'd
say the answer to your question is yes, you do need to subclass QUndoCommand
for each kind of command you want to make undoable.

You need to derive a subclass because you need to implement undo() and
redo() methods that perform the work of adding the text to the file (redo)
and removing it (undo). You might optionally write text back to the field
when performing an undo command, as well.

I've put some example code on this page:

http://www.diotavelli.net/PyQtWiki/Undo_and_redo_with_line_edits

It's not ideal because the commands are invoked when the window itself
loses focus, but perhaps you can use it as a starting point.

David
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,995
Messages
2,570,226
Members
46,815
Latest member
treekmostly22

Latest Threads

Top