trayiconContextMenu = QtGui.QMenu()
trayiconContextMenu.addAction("Exit")
trayicon.setContextMenu(trayiconContextMenu)
In pyqt, a context menu is attached to the system tray icon.
In a particular scenario, application exit is called internally, but at that time if the system tray menu is popped up manually, application will not be exit.
After pressing Esc key or clicking mouse in some other app (i.e) when tray menu is hidden, application exit will be called with errors.
trayiconContextMenu.hide()
/*does not work in my above case.*/
trayicon.hide()
/*hides tray icon alone but not the tray menu*/
Also for same scenario app exit works properly when tray menu is not popped up.
Help would be appreciated much.
The
QSystemTrayIcondoesn’t take ownership of the menu when you set it, so you might need to take steps to ensure it is deleted properly.Try something like this: