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] Best way to activate the correct QUndoStack

[solved] Best way to activate the correct QUndoStack

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 1.2k Views
  • 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
    Wurgl
    wrote on last edited by
    #1

    Hello!

    I am writing some application which has a QTreeView and a QMdiArea. Inside that QMdiArea are Widgets having a QUndoStack which are managed by a QUndoGroup. In addition when clicking/selecting some area inside those Widgets another Widget is shown, holding additional information for that last clicked element.

    As long as I have a QUndoStack just for those Widgets inside the QMdiArea eveything works fine and the QUndoStacks are managed fine by QUndoGroup.

    Now I tried to add another QUndoStack to that QTreeView and here my problem starts.

    Currently I am using focusInEvent() to switch to the QUndoStack of the QTreeView. But what is the best way to switch back to the QUndoStack of those QWidgets inside that QMdiArea? There is no problem when the user clicks on that QWidgets, I can handle that with focusInEvent() too. But when the user clicks on those windows with additional information, it seems that I need focusInEvent() for every single element in those windows which seems to be a lot of typing and seems to be error-prone (simple because more code and because it may be forgotten).

    Another idea was to use focusOutEvent() in the QTreeView, but that would mean that the menubar which shows undo/redo Actions would switch the focus of these Undo/Redo Actions too, causing unexpected behavior.

    I think that enterEvent() in the QMdiArea is not a good idea, the user might click on the QTreeView and simple move the mouse somewhere, that shall not switch to a QUndoStack of a different context.

    Any better ideas?

    BTW: I use a QMainWindow (with the QMdiArea) inside another QMainWindow (which hold that QTreeView) because of requirements for docking elements.

    1 Reply Last reply
    0
    • SGaistS Offline
      SGaistS Offline
      SGaist
      Lifetime Qt Champion
      wrote on last edited by
      #2

      Hi,

      You can use an eventFilter in your QMdiArea and react on the focus event of all the widgets in there

      Hope it helps

      Interested in AI ? www.idiap.ch
      Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

      1 Reply Last reply
      0
      • W Offline
        W Offline
        Wurgl
        wrote on last edited by
        #3

        QMdiArea::focusInEvent() is called only when I click into the gray background, not when clicking on some Widget in it :-( And it is also not called for dockable widgets.

        And yes, setFocusPolicy(Qt::WheelFocus); gets called in its constructor ((Qt::WheelFocus might be to much, will change this later …))

        1 Reply Last reply
        0
        • SGaistS Offline
          SGaistS Offline
          SGaist
          Lifetime Qt Champion
          wrote on last edited by
          #4

          That I understood, that's why I suggested "eventFilter":http://doc.qt.io/qt-5/qobject.html#eventFilter you make your QMdiArea the filter for all the widgets inside it and then you can react on the focusIn event of all of them

          Interested in AI ? www.idiap.ch
          Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

          1 Reply Last reply
          0
          • W Offline
            W Offline
            Wurgl
            wrote on last edited by
            #5

            Hmm ... oops … okay … will try that tomorrow, now it is time for a good beer ;^)

            1 Reply Last reply
            0
            • W Offline
              W Offline
              Wurgl
              wrote on last edited by
              #6

              Did take a little bit longer, but works now.

              The main difference is subclassing, which I do not need now.

              Thanks!

              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