0

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_())
Mark
  • 672
  • 1
  • 6
  • 19
  • Is there a reason that you can't use a [`QDockWidget`](https://doc.qt.io/qt-5/qdockwidget.html) – Umbral Reaper May 12 '21 at 09:13
  • I am using a QDockWidget. I am embedding another QMainWindow because I want to create docks within the embedded QMainWindow also – Mark May 12 '21 at 09:17

0 Answers0