QSystemTrayIcon don`t emit signal "activated" when the icon clicked. I read that in the previous version it was a bug, but it should have been corrected.
I have Qt 5.5.0 + Ubuntu 14.04 (Gnome).
tray.h
{
Q_OBJECT
public:
explicit MainWindow
(QWidget *parent
= 0);
~MainWindow();
private slots:
private:
};
class MainWindow : public QMainWindow
{
Q_OBJECT
public:
explicit MainWindow(QWidget *parent = 0);
~MainWindow();
private slots:
void showMsg(QSystemTrayIcon::ActivationReason reason);
private:
QSystemTrayIcon *trIcon;
QAction *actClose;
QMenu *menu;
};
To copy to clipboard, switch view to plain text mode
tray.cpp
...
MainWindow::MainWindow(QWidget *parent
) : {
actClose
= new QAction("Close",
this);
...
this->menuBar()->setNativeMenuBar(false);
menu = menuBar()->addMenu(tr("&File"));
menu->addAction(actClose);
trIcon
->setIcon
(QIcon(":/main_icon.png"));
trIcon->setContextMenu(menu);
connect(trIcon, &QSystemTrayIcon::activated, this, &MainWindow::showMsg);
trIcon->show();
}
MainWindow::~MainWindow()
{
}
{
qDebug() << "show message";
}
...
MainWindow::MainWindow(QWidget *parent) :
QMainWindow(parent)
{
actClose = new QAction("Close", this);
...
this->menuBar()->setNativeMenuBar(false);
menu = menuBar()->addMenu(tr("&File"));
menu->addAction(actClose);
trIcon = new QSystemTrayIcon(this);
trIcon->setIcon(QIcon(":/main_icon.png"));
trIcon->setContextMenu(menu);
connect(trIcon, &QSystemTrayIcon::activated, this, &MainWindow::showMsg);
trIcon->show();
}
MainWindow::~MainWindow()
{
}
void MainWindow::showMsg(QSystemTrayIcon::ActivationReason reason)
{
qDebug() << "show message";
}
To copy to clipboard, switch view to plain text mode
Anybody have any idea? Thank)
Bookmarks