[SOLVED] create Undo/Redo actions

  • Hello. I'm trying to use qt undo/redo functionality in my app. I read example documentation and follow steps:

    1. Create stack and Undo/redo actions

    undoStack = new QUndoStack(this);
    QAction *undoAction = undoStack->createUndoAction(this, tr("&Undo"));

    QAction *redoAction = undoStack->createRedoAction(this, tr("&Redo"));


    1. When I close tab (QTabWidget) this code executes

    QUndoCommand *ucCloseTab = new CloseTabCommand(this, (QTabWidget *)ui.tabWidget->widget(TabNumber), ui.treeForms->topLevelItem(TabNumber), NULL);

    After push executes redo() of my QUndoCommand class. But actions undo and redo in menu still disabled. Should they enable automatically, when undoStack is not empty? If I set it enabled, triggering actions doesn't execute undo() or redo(). Thanks

  • Moderators

    you need to connect your action to the undo-stack object:
    connect(undoStack , SIGNAL(canRedoChanged(bool)), redoAction, SLOT(setEnabled(bool)));
    and of course do the same analog for undoAction.

Log in to reply

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.