QMdiSubWindow geometry and size save and restore
-
Good morning,
today I struggle with saving and restoring those sub windows. I'd find it useful to save size and geometry of those.The case: I have literally three sub windows at most, each is QMdiSubWindow with a custom (each time different) descendant of QWidget set as a widget. I add them simply by invoking QMdiArea->addSubWindow().
Since I could not find a signal in QMdiArea nor in QMdiSubWindow that would notify me if the sub window is about to close... I could write a class based on QMdiSubWindow and override onClose() but would that require me to overwrite QMdiArea as well or simple object cast when addSubWindow() is used will suffice?
Or is there any other way to catch the moment of closing?
I am using Qt 5.15.2
Many thanks in advance.
-
Hi
What about an event filter?https://stackoverflow.com/questions/8818297/qt-how-to-know-when-a-qmdisubwindow-is-closed
not that subclassing QMdiSubWindow is a bad idea and im sure you can use it
with minimal casting to use with the std. QMdiArea -
Hi
What about an event filter?https://stackoverflow.com/questions/8818297/qt-how-to-know-when-a-qmdisubwindow-is-closed
not that subclassing QMdiSubWindow is a bad idea and im sure you can use it
with minimal casting to use with the std. QMdiArea -
@mrjj Thank you for clarifying. Will test both. I never used event filters before, seems like a learning opportunity.
@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.
-
@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.
-
@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?@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. -
@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. -
@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. -
@mrjj but calling close() on each of opened sub windows doesn't call the eventFilter on any of them.
@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. -
@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.@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.
-
@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.
-
@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.
-
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()
@artwaw
Hi
excellent :)Just as a note. If you get very into Docks then please notice
https://github.com/githubuser0xFFFF/Qt-Advanced-Docking-Systemas It can dock to central/center, a feature which often is much loved when you want such setup.