Question

I have an issue with a QSystemTrayIcon application I'm working on.

Any dialog box that I make with the SystemTrayIcon as parent or grandparent will terminate the entire application when closed, even when I override the "reject" method.

Here is a simplified example with no icon. When you run it (Windows 7 here) you should have a blank tray icon application on the task bar. If you left click it, an empty Dialog box will pop up. Clicking the "X" to close the dialog will also completely terminate the python process.

from PySide import QtGui, QtCore   
class RestartDialog(QtGui.QDialog):
    def __init__(self, parent):
        super(RestartDialog, self).__init__()

    def reject(self):
        self.hide()

class SystemTrayIcon(QtGui.QSystemTrayIcon):

    def __init__(self, parent=None):
        QtGui.QSystemTrayIcon.__init__(self, parent)
        self.activated.connect(self.click_trap)

    def click_trap(self, value):
        ''' Left click tray function '''
        if value == self.Trigger: #left click!
            self.dialog = RestartDialog(self)
            self.dialog.show()

    def show(self):
        QtGui.QSystemTrayIcon.show(self)


if __name__ == "__main__":
    proc = QtGui.QApplication([])
    APP = SystemTrayIcon()
    APP.show()
    proc.exec_()
Was it helpful?

Solution

Try adding this after creating your QApplication:

proc.setQuitOnLastWindowClosed(False)

It is true by default, so your eventloop will terminate after you close the dialog.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top