The behaviour I am wanting is to have multiple QMainWindows, docked within a top-level window. The docked windows will present some aspect of the application and I need to know when they close, but Qt only issues the closeEvent when a top-level widget is closed. How can I do the equivalent on a nested QMainWindow? Illustrative code sample below
import sys
from PySide2.QtCore import Qt
from PySide2.QtWidgets import QApplication, QMainWindow, QDockWidget
class MainWindow(QMainWindow):
def __init__(self, inside:QMainWindow=None):
QMainWindow.__init__(self)
if inside:
dock = QDockWidget()
dock.setWidget(self)
inside.addDockWidget(Qt.TopDockWidgetArea, dock)
self.show()
def closeEvent(self, event):
# This is only for a top-level widget. How to know then the inner window closes?
print("closeEvent")
event.accept()
if __name__ == '__main__':
app = QApplication.instance() or QApplication()
m1 = MainWindow()
m2 = MainWindow(m1)
sys.exit(app.exec_())