I am using Ubuntu 12.04 and, while I can create a tray icon with a usable 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();
The clickSysTrayIcon(QSystemTrayIcon::ActivationReason) is the following:
void MainWindow::clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
//reason is a variable that holds the type of activation or click done on the icon tray
qDebug() << "I'm in!";
}
and, defined at the header file as:
private Q_SLOTS:
void clickSysTrayIcon(QSystemTrayIcon::ActivationReason reason);
However, I cannot get the “I’m in!” message to be shown. I’ve tried to make it work with left/right clicks, with middle click and with mouse wheel, but I never see this message being outputed.
What is wrong?
EDIT: It seems that something’s wrong with the specific system, Ubuntu 12.04, because it doesn’t use tray icons any more and only indicators. So, there’s a program which uses the tray icons and they convert them into indicators. But, then the features of indicators are gone. I know that it’s the system to blame, because the same program, under the very same code, works perfectly under Lubuntu 12.04 with the LXDE desktop.
I blame Ubuntu for this. The sni-qt package doesn’t do a very good migration from tray icons to indicators, providing that indicators can interact on click, on roller etc. It’s a shame!
Any solutions to this problem?
My bounty ends, so if there’s someone who can address the problem I would be thankful!
Bring up the issue to the people that have the most influence on the projects.
https://help.ubuntu.com/community/ReportingBugs#How_to_report_bugs
https://bugreports.qt.io/
Work-Around
I would make a floating frameless qwidget on top of the indicator area where your indicator gets painted, and then add the appropriate mouseEvent functions on to it.
Here is starting point for this style of work-around. I don’t know how kosher this is, but it works pretty well in Windows. I know there are some UI tweaks and tools for Windows that use this style of layered elements, like DisplayFusion and TeamViewer. I haven’t tested it in Ubuntu yet, but it should work the same way.
and here is the main function…