PyQt's QMainWindow closeEvent is never called

后端 未结 2 1973
说谎
说谎 2021-01-03 09:06

I\'m using pyqt4 in python.
When I close the QMainWindow window , its not handled by closeEvent method. Please someone tell me what is wrong with this cod

2条回答
  •  滥情空心
    2021-01-03 09:57

    This is my solution,

        def closeEvent(self, e):
            close = QMessageBox.question(
                self,
                "Close Application",
                "Are you sure?",
                QMessageBox.Yes | QMessageBox.No,
                QMessageBox.No
            )
            e.ignore()
            if close == QMessageBox.Yes:
                e.accept()
    

提交回复
热议问题