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. QLineEdit undo/redo does not work from my edit menu
Forum Updated to NodeBB v4.3 + New Features

QLineEdit undo/redo does not work from my edit menu

Scheduled Pinned Locked Moved Unsolved General and Desktop
4 Posts 2 Posters 1.1k 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.
  • C Offline
    C Offline
    Chris Bare
    wrote on last edited by
    #1

    I am working with Qt5 and have implemented an undo stack for my application.

    undoStack = new QUndoStack ();
    undoStack->setUndoLimit (100);
    

    I build my undo/redo menu items like 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);
    

    All of which works fine when I push my commands onto the undo stack. However when a user types into a QLineEdit the insert commands don't know about my undoStack. I assume there is some internal stack, but I don't know how to access it.
    The result is that the user can type ctrl-Z in the QLineEdit and it will undo, but if they try to use the undo menu item, it knows nothing about the recent edits and undoes some earlier application action.

    I looked at the code for QLineEdit, but it is using internal objects which I could not even find:

    void QLineEdit::undo()
    {
        Q_D(QLineEdit);
        d->resetInputMethod();
        d->control->undo();
    }
    

    Is there a way to tell the QLineEdit to use my undoStack?

    A 1 Reply Last reply
    0
    • C Chris Bare

      I am working with Qt5 and have implemented an undo stack for my application.

      undoStack = new QUndoStack ();
      undoStack->setUndoLimit (100);
      

      I build my undo/redo menu items like 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);
      

      All of which works fine when I push my commands onto the undo stack. However when a user types into a QLineEdit the insert commands don't know about my undoStack. I assume there is some internal stack, but I don't know how to access it.
      The result is that the user can type ctrl-Z in the QLineEdit and it will undo, but if they try to use the undo menu item, it knows nothing about the recent edits and undoes some earlier application action.

      I looked at the code for QLineEdit, but it is using internal objects which I could not even find:

      void QLineEdit::undo()
      {
          Q_D(QLineEdit);
          d->resetInputMethod();
          d->control->undo();
      }
      

      Is there a way to tell the QLineEdit to use my undoStack?

      A Offline
      A Offline
      ambershark
      wrote on last edited by
      #2

      @Chris-Bare You could do a check when your undo menu action is triggered to see if the focus is on the QLineEdit, and if so you could then call yourLineEdit->undo() directly. This would bypass your stack and act appropriately on the line edit. Same with redo but call redo().

      My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

      C 1 Reply Last reply
      0
      • A ambershark

        @Chris-Bare You could do a check when your undo menu action is triggered to see if the focus is on the QLineEdit, and if so you could then call yourLineEdit->undo() directly. This would bypass your stack and act appropriately on the line edit. Same with redo but call redo().

        C Offline
        C Offline
        Chris Bare
        wrote on last edited by
        #3

        @ambershark That would sort-of work, but the undo action would still not show up in the undo list viewer.

        A 1 Reply Last reply
        0
        • C Chris Bare

          @ambershark That would sort-of work, but the undo action would still not show up in the undo list viewer.

          A Offline
          A Offline
          ambershark
          wrote on last edited by
          #4

          @Chris-Bare Oh, so you want the whole undo experience managed in your QUndoStack. In that case you are going to have to derive from QLineEdit and implement your undostack there. From what I can tell there is no way to access it inside the base QLineEdit.

          My L-GPL'd C++ Logger github.com/ambershark-mike/sharklog

          1 Reply Last reply
          1

          • Login

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