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. QMdiSubWindow geometry and size save and restore
Forum Update on Monday, May 27th 2025

QMdiSubWindow geometry and size save and restore

Scheduled Pinned Locked Moved Solved General and Desktop
qmdiareaqmdisubwindow
13 Posts 2 Posters 1.4k 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.
  • A artwaw
    13 May 2021, 10:31

    @mrjj Thank you for clarifying. Will test both. I never used event filters before, seems like a learning opportunity.

    M Offline
    M Offline
    mrjj
    Lifetime Qt Champion
    wrote on 13 May 2021, 10:40 last edited by mrjj
    #4

    @artwaw
    well event filters are handy for catching events from outside in cases where subclassing might be a bit invasive to existing code or subclassing would be a bit massive if many types of widgets are involved.

    That said, one has to take care not to eat events by accident.

    https://doc.qt.io/qt-5/eventsandfilters.html

    A 1 Reply Last reply 13 May 2021, 11:02
    1
    • M mrjj
      13 May 2021, 10:40

      @artwaw
      well event filters are handy for catching events from outside in cases where subclassing might be a bit invasive to existing code or subclassing would be a bit massive if many types of widgets are involved.

      That said, one has to take care not to eat events by accident.

      https://doc.qt.io/qt-5/eventsandfilters.html

      A Offline
      A Offline
      artwaw
      wrote on 13 May 2021, 11:02 last edited by
      #5

      @mrjj Event filter works nicely when mdi sub window is closed and restored but there is one edge case:
      when closing application with sub window open it is not called at all. Any hint you can offer how to get past that?

      M 1 Reply Last reply 13 May 2021, 11:07
      0
      • A artwaw
        13 May 2021, 11:02

        @mrjj Event filter works nicely when mdi sub window is closed and restored but there is one edge case:
        when closing application with sub window open it is not called at all. Any hint you can offer how to get past that?

        M Offline
        M Offline
        mrjj
        Lifetime Qt Champion
        wrote on 13 May 2021, 11:07 last edited by
        #6

        @artwaw
        Hi
        Well i guess any open windows are just deleted, not closed as such, when whole app exits.

        One way could be to override closeEvent for the mainwindow and
        loop over the windows (ui->mdiArea->subWindowList ) , calling close() on each
        to have the event code handle it like they were manually closed.

        A 2 Replies Last reply 13 May 2021, 11:09
        1
        • M mrjj
          13 May 2021, 11:07

          @artwaw
          Hi
          Well i guess any open windows are just deleted, not closed as such, when whole app exits.

          One way could be to override closeEvent for the mainwindow and
          loop over the windows (ui->mdiArea->subWindowList ) , calling close() on each
          to have the event code handle it like they were manually closed.

          A Offline
          A Offline
          artwaw
          wrote on 13 May 2021, 11:09 last edited by
          #7

          @mrjj Yes. Why didn't I thought of that? Thank you, you're a star!

          1 Reply Last reply
          1
          • M mrjj
            13 May 2021, 11:07

            @artwaw
            Hi
            Well i guess any open windows are just deleted, not closed as such, when whole app exits.

            One way could be to override closeEvent for the mainwindow and
            loop over the windows (ui->mdiArea->subWindowList ) , calling close() on each
            to have the event code handle it like they were manually closed.

            A Offline
            A Offline
            artwaw
            wrote on 13 May 2021, 11:15 last edited by
            #8

            @mrjj but calling close() on each of opened sub windows doesn't call the eventFilter on any of them.

            M 1 Reply Last reply 13 May 2021, 11:19
            1
            • A artwaw
              13 May 2021, 11:15

              @mrjj but calling close() on each of opened sub windows doesn't call the eventFilter on any of them.

              M Offline
              M Offline
              mrjj
              Lifetime Qt Champion
              wrote on 13 May 2021, 11:19 last edited by
              #9

              @artwaw
              Hi
              Ah yes. my bad. sorry. the close() function is a direct method.
              So move the inner saving code to a function that takes a QMdiSubWindow *
              and call that from closeEvent pr Window.

              You could also use
              QCoreApplication::postEvent
              to send a close to them.

              A 1 Reply Last reply 13 May 2021, 11:42
              0
              • M mrjj
                13 May 2021, 11:19

                @artwaw
                Hi
                Ah yes. my bad. sorry. the close() function is a direct method.
                So move the inner saving code to a function that takes a QMdiSubWindow *
                and call that from closeEvent pr Window.

                You could also use
                QCoreApplication::postEvent
                to send a close to them.

                A Offline
                A Offline
                artwaw
                wrote on 13 May 2021, 11:42 last edited by
                #10

                @mrjj it's interesting how it doesn't work.
                I tried both postEvent and sendEvent, the former with normal and high priority - to no avail.

                What's even more interesting for me here is that when mdi sub window is getting closed independently the internal widget's closeEvent() is being processed. When I just close the application with sub windows opened their closeEvent()s are not called at all - so implementing custom class based on QMdiSubWindow and overriding its closeEvent() makes no sense too.

                I am truly puzzled now.

                A 2 Replies Last reply 13 May 2021, 12:01
                0
                • A artwaw
                  13 May 2021, 11:42

                  @mrjj it's interesting how it doesn't work.
                  I tried both postEvent and sendEvent, the former with normal and high priority - to no avail.

                  What's even more interesting for me here is that when mdi sub window is getting closed independently the internal widget's closeEvent() is being processed. When I just close the application with sub windows opened their closeEvent()s are not called at all - so implementing custom class based on QMdiSubWindow and overriding its closeEvent() makes no sense too.

                  I am truly puzzled now.

                  A Offline
                  A Offline
                  artwaw
                  wrote on 13 May 2021, 12:01 last edited by
                  #11
                  This post is deleted!
                  1 Reply Last reply
                  0
                  • A artwaw
                    13 May 2021, 11:42

                    @mrjj it's interesting how it doesn't work.
                    I tried both postEvent and sendEvent, the former with normal and high priority - to no avail.

                    What's even more interesting for me here is that when mdi sub window is getting closed independently the internal widget's closeEvent() is being processed. When I just close the application with sub windows opened their closeEvent()s are not called at all - so implementing custom class based on QMdiSubWindow and overriding its closeEvent() makes no sense too.

                    I am truly puzzled now.

                    A Offline
                    A Offline
                    artwaw
                    wrote on 13 May 2021, 12:11 last edited by
                    #12

                    All sorted. I made mistakes somewhere else and as a result closeEvent() of QMainWindow has not been called - once I fixed that everything works as per proposed solution with QCoreApplication::postEvent()

                    M 1 Reply Last reply 13 May 2021, 12:15
                    1
                    • A artwaw
                      13 May 2021, 12:11

                      All sorted. I made mistakes somewhere else and as a result closeEvent() of QMainWindow has not been called - once I fixed that everything works as per proposed solution with QCoreApplication::postEvent()

                      M Offline
                      M Offline
                      mrjj
                      Lifetime Qt Champion
                      wrote on 13 May 2021, 12:15 last edited by
                      #13

                      @artwaw
                      Hi
                      excellent :)

                      Just as a note. If you get very into Docks then please notice
                      https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-System

                      as It can dock to central/center, a feature which often is much loved when you want such setup.

                      1 Reply Last reply
                      1

                      13/13

                      13 May 2021, 12:15

                      • Login

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