Created
September 12, 2017 11:21
-
-
Save anonymous/2f1498183267e6776efa5cf6cf0f97c6 to your computer and use it in GitHub Desktop.
Qt catch closeEvent example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python | |
# -*- coding: utf-8 -*- | |
import sys | |
from PyQt4 import QtGui | |
class MyWindow(QtGui.QMainWindow): | |
def closeEvent(self, event): | |
if self.showDialog(): | |
event.accept() | |
else: | |
event.ignore() | |
def showDialog(self): | |
msg = QtGui.QMessageBox() | |
msg.setText('Do you really want to Exit?') | |
msg.setStandardButtons(QtGui.QMessageBox.Ok | QtGui.QMessageBox.Cancel) | |
retval = msg.exec_() | |
if retval == QtGui.QMessageBox.Ok: | |
return True | |
else: | |
return False | |
def main(): | |
app = QtGui.QApplication(sys.argv) | |
w = MyWindow() | |
w.resize(250, 150) | |
w.move(300, 300) | |
w.setWindowTitle('Exit Test') | |
w.show() | |
sys.exit(app.exec_()) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment