How do I get a signal to close the main window?
-
Hi!
How do I get a signal to close the main window?
If I open another window but close the main window, I don't get these closing signals:self.ui.destroyed.connect(lambda : print(6666666)) self.destroyed.connect(lambda: print(777777777777))My class:
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.ui = uic.loadUi("mainWindow.ui")And not work event :
def closeEvent(self, event): print("closeEvent") -
Hi!
How do I get a signal to close the main window?
If I open another window but close the main window, I don't get these closing signals:self.ui.destroyed.connect(lambda : print(6666666)) self.destroyed.connect(lambda: print(777777777777))My class:
class MainWindow(QMainWindow): def __init__(self): super(MainWindow, self).__init__() self.ui = uic.loadUi("mainWindow.ui")And not work event :
def closeEvent(self, event): print("closeEvent")@Mikeeeeee
What are you looking for an answer?If I open another window but close the main window, I don't get these closing signals:
Qt has a default behaviour of quitting application when the last window is closed, like if you just have a main window. If you have another window open that won't get fired.
-
@Mikeeeeee
If you want to know when aQWidgetis closed, you can sub-class and override thecloseEvent(). Closing in itself does not emit any signal, so that is the way to recognise it. -
@Mikeeeeee
If you want to know when aQWidgetis closed, you can sub-class and override thecloseEvent(). Closing in itself does not emit any signal, so that is the way to recognise it. -
@Mikeeeeee
You don't, it's not aQWidget!self.uiitself does not close or send signals etc. It owns widgets which do. -
@Mikeeeeee
You don't, it's not aQWidget!self.uiitself does not close or send signals etc. It owns widgets which do. -
@Mikeeeeee
What class isui.mainWindow? It needs to be your class derived fromQMainWindow. Then you go override that class'scloseEvent().I see https://stackoverflow.com/questions/22460003/pyqts-qmainwindow-closeevent-is-never-called is for PyQt4, but look at the solution, I imagine it will be similar for PyQt5/PySide2.