Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Update: Forum Guidelines & Code of Conduct

    [solved] Best way to activate the correct QUndoStack

    General and Desktop
    2
    6
    1054
    Loading More Posts
    • 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
      Wurgl last edited by

      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 Reply Quote 0
      • SGaist
        SGaist Lifetime Qt Champion last edited by

        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 Reply Quote 0
        • W
          Wurgl last edited by

          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 Reply Quote 0
          • SGaist
            SGaist Lifetime Qt Champion last edited by

            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 Reply Quote 0
            • W
              Wurgl last edited by

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

              1 Reply Last reply Reply Quote 0
              • W
                Wurgl last edited by

                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 Reply Quote 0
                • First post
                  Last post