覆盖主窗口中的 closeEvent
方法
QWidget。
例如:
class MainWindow(QWidget): # or QMainWindow ... def closeEvent(self, event): # do stuff if can_exit: event.accept() # let the window close else: event.ignore()
另一种可能性是使用
QApplication的
aboutToQuit
信号,如下所示:
app = QApplication(sys.argv)app.aboutToQuit.connect(myExitHandler) # myExitHandler is a callable



