Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. [SOLVED] create Undo/Redo actions
Forum Updated to NodeBB v4.3 + New Features

[SOLVED] create Undo/Redo actions

Scheduled Pinned Locked Moved General and Desktop
2 Posts 2 Posters 1.3k Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    WoldemarShiPa
    wrote on last edited by
    #1

    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"));
    undoAction->setShortcuts(QKeySequence::Undo);

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

    ui.menuEdit->addAction(undoAction);
    ui.menuEdit->addAction(redoAction);

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

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

    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

    1 Reply Last reply
    0
    • raven-worxR Offline
      raven-worxR Offline
      raven-worx
      Moderators
      wrote on last edited by
      #2

      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.

      --- SUPPORT REQUESTS VIA CHAT WILL BE IGNORED ---
      If you have a question please use the forum so others can benefit from the solution in the future

      1 Reply Last reply
      0

      • Login

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • Users
      • Groups
      • Search
      • Get Qt Extensions
      • Unsolved