Python PyQt4关闭应用程序

时间:2012-09-16 02:19:52

标签: python dialog qt4 python-2.7 pyqt4

我想知道,关闭对话框的最佳或首选方法是什么。假设我的主窗口,设置和帮助窗口已打开。用户决定退出主窗口,那么如何拦截信号以及关闭打开的窗口的最佳方法是什么?

使用dialogMain.close()是否足够好?

1 个答案:

答案 0 :(得分: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()
相关问题