2012-09-16 56 views
-2

我想知道,什麼是最好的或首選的方式來關閉對話框。假設我打開了我的主窗口,設置和幫助窗口。用戶決定退出主窗口,那麼如何攔截信號以及關閉打開的窗口的最佳方式是什麼?Python PyQt4關閉應用程序

是否使用dialogMain.close()夠好?

回答

1

您可以覆蓋closeEvent方法:

class YourApplication(QMainWindow): 
    # ... 

    def closeEvent(self, event): 
    if condition: 
     if QMessageBox.question(self, 'Your Application', 'Are you sure you want to exit?', QMessageBox.Yes, QMessageBox.No) == QMessageBox.Yes: 
     # Do anything before the application closes 

     event.accept() 
     else: 
     event.ignore()