We're writing a Python plugin for QGIS 2.8.3. I've derived a class from QUndoCommand to contain "undo-able" work. When I push it onto the undo stack, its redo method gets called as expected, but QGIS doesn't call the undo method when I click Undo in the Undo/Redo History widget, nor call the redo method again when I click Redo.

The code looks like:

class TestUndoCommand(QUndoCommand):
    def __init__(self):
        super(TestUndoCommand, self).__init__("TestUndoCommand")

    def redo(self):
        super(TestUndoCommand, self).redo()
        QMessageBox.information(None, "Redo", "Redo")

    def undo(self):
        super(TestUndoCommand, self).undo()
        QMessageBox.information(None, "Undo", "Undo")

undoAddCmd = TestUndoCommand()

What am I missing?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.