I am using Ubuntu 12.04 and although I can create a tray icon with a useful menu, I cannot control its actions:
trayIcon = new QSystemTrayIcon(this); trayIcon->setIcon(QIcon(":/icons/Pictures/icon.png")); trayIcon->setToolTip(QString("Hello there...")); connect(trayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(clickSysTrayIcon(QSystemTrayIcon::ActivationReason))); connect(this,SIGNAL(minimized()),this,SLOT(hide()),Qt::QueuedConnection); QMenu *changer_menu = new QMenu; Show_action = new QAction(tr("S&how"),this); Show_action->setIconVisibleInMenu(true); connect(Show_action, SIGNAL(triggered()), this, SLOT(showClicked())); changer_menu->addAction(Show_action); changer_menu->addSeparator(); Quit_action = new QAction(tr("&Quit"), this); Quit_action->setIconVisibleInMenu(true);; connect(Quit_action, SIGNAL(triggered()), this, SLOT(close_minimize())); changer_menu->addAction(Quit_action); trayIcon->setContextMenu(changer_menu); trayIcon->show();
ClickSysTrayIcon (QSystemTrayIcon :: ActivationReason) is as follows:
void MainWindow::clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason) {
and, defined in the header file as:
private Q_SLOTS: void clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason);
However, I canโt get "I'm in!". message to be displayed. I tried to make it work with left / right clicks, with a middle click and with the mouse wheel, but I never see this message being displayed.
What's wrong?
EDIT: There seems to be something wrong with the specific system, Ubuntu 12.04, because it no longer uses tray icons and only indicators. So, there is a program that uses tray icons and converts them into indicators. But then the functions of the indicators disappeared. I know that this system is to blame, because the same program under the same code works fine under Lubuntu 12.04 with the LXDE desktop.
I blame Ubuntu for this. The sni-qt package does not move very well from tray icons to indicators, ensuring that indicators can interact when pressed, on rollers, etc. It's a shame! Any solutions to this problem?
My reward ends, so if there is someone who can solve the problem, I would be grateful!