I'm writing an application in C++ with Qt that utilizes the system tray. I have implemented the system tray using a QSystemTrayIcon class as shown in the examples, but it doesn't have the same behavior as other system tray icons that are present on my computer. For instance, I have Spotify installed on Ubuntu 12.04 and it shows a system tray icon with a drop down menu. With my application, it shows a system tray icon with a context menu, meaning you have to right click it to make the menu active. With Spotify, all that needs to be done is to click on the icon and the menu will show. What can I do to get native system tray icons in Ubuntu? I'm fine with using specific code for X11/Linux and not the built-in Qt functions. Thanks much.
Here's my code:
void MainWindow::closeEvent(QCloseEvent *event)
{
if (trayIcon->isVisible()) {
hide();
event->ignore();
}
}
void MainWindow::createActions()
{
restoreAction = new QAction(tr("&Show"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(show()));
quitAction = new QAction(tr("&Exit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void MainWindow::createTrayIcon()
{
trayIconMenu = new QMenu(this);
accountsMenu = trayIconMenu->addMenu(tr("Accounts"));
trayIconMenu->addSeparator();
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
}