When I run and exit my applications, it leaves too many tray icons in the tray instead of just one. I have also setup my application so only one instances can be instantiated at one time but still after several start and exit of the program, system tray seems to accommodate all the icons which than slowly drops when I hover mouse on them to last (legit) one. How can I stop creating this duplicate icons?
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent),
ui(new Ui::MainWindow)
{
ui->setupUi(this);
systemTray = new QSystemTrayIcon();
systemTray->setIcon( QIcon(":icons/Resources/Orange.ico") );
systemTray->setVisible( true );
systemTray->show();
systemTray->setToolTip("Rigaku sync application");
systemTrayIconMenu = new QMenu();
systemTrayIconMenu->addAction( ui->actionOpen_App );
systemTrayIconMenu->addAction( ui->actionSettings );
systemTrayIconMenu->addAction( ui->actionClose );
systemTrayIconMenu->addAction( ui->actionQuit );
systemTray->setContextMenu( systemTrayIconMenu );
}
I delete the systemTray
pointer in the destructor.
Since we at it, I also want to be able to double click the tray icon which should bring up the app. How can I do that? I understand I have to setup default option on double click (which also appears bold in context menu) but how can I do that? Thanks!
Update
I can show the default menu now with setDefaultAction() and double click on tray. Now my only issue is how to get rid of extra icons in system tray.