Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to implement the "exit" action in PyQt4?

Tags:

python

exit

pyqt4

Many software have an "exit" action in the menubar items. I wonder know how to implement it in pyqt4.

I think only invoking the method QtCore.QCoreApplication.quit() is not enough, because the application main window doesn’t disappear immediately when this method is called.

I think in order to "exit", we shouldn’t only call the quit() method but also should close the application main window at the same time.

What do you think ?

like image 973
iMath Avatar asked Dec 13 '25 19:12

iMath


1 Answers

By default, the application will quit when the last window is closed - unless quitOnLastWindowClosed has been set to False.

So it is normally enough to just call close() on the main window.

One other thing to think about here, though, is whether any final actions should be taken before the application closes down (e.g. saving settings, asking the user whether they want to save any modified documents, etc).

So it is also common to reimplement the main window's closeEvent function.

like image 165
ekhumoro Avatar answered Dec 15 '25 08:12

ekhumoro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!