GLHF GLHF - 5 months ago 36
Python Question

PyQt5 destroy a program properly

I'm using

self.setWindowFlags(Qt.Tool)
to hide the application on task bar. However, I realized that even I press
x
on the right-top corner of the program, it's still running on the background ( I see it on task manager/processes). So that means the program doesn't close properly. Is this because I use
self.setWindowFlags(Qt.Tool)
? How can I fix this, that flag option hide program's icon but even if I press
x
to close the program, it's still running on the background.

Answer

I found the solution, make your own quit button and connect the signal like below

self.xbutton = QPushButton(self)
self.xbutton.setText("Quit")
self.xbutton.clicked.connect(self.close)

This destroy the app properly. Also instead of Qt.Tool use self.setWindowFlags(QtCore.Qt.FramelessWindowHint)