【问题标题】:Python PyQt4 closing the applicationPython PyQt4 关闭应用程序
【发布时间】:2012-09-16 02:19:51
【问题描述】:

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

dialogMain.close()的使用够好吗?

【问题讨论】:

    标签: python dialog qt4 python-2.7 pyqt4


    【解决方案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()
    

    【讨论】:

      猜你喜欢
      • 2014-07-25
      • 1970-01-01
      • 1970-01-01
      • 2012-05-04
      • 1970-01-01
      • 2010-12-16
      • 1970-01-01
      • 1970-01-01
      • 2023-03-03
      相关资源
      最近更新 更多