app
::app(QWidget *parent, Qt
::WFlags flags
){
...
createActions();
createTrayIcon();
trayIcon
->setIcon
(QIcon(QString::fromUtf8(":/app/Resources/Add.png")));
trayIcon->show();
...
}
void app::createActions()
{
minimizeAction
= new QAction(tr
("Mi&nimize"),
this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
restoreAction
= new QAction(tr
("&Restore"),
this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction
= new QAction(tr
("&Quit"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void HSM::createTrayIcon()
{
trayIconMenu
= new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setToolTip(tr("My app"));
}
void app::createActions()
{
minimizeAction
= new QAction(tr
("Mi&nimize"),
this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
restoreAction
= new QAction(tr
("&Restore"),
this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction
= new QAction(tr
("&Quit"),
this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void app::showMessage()
{
trayIcon->showMessage(tr("My app"), tr("Some msg"), icon, 100);
}
{
switch (reason)
{
show();
break;
show();
break;
showMessage();
break;
default:
;
}
}
app::app(QWidget *parent, Qt::WFlags flags)
: QDialog(parent, flags)
{
...
createActions();
createTrayIcon();
trayIcon->setIcon(QIcon(QString::fromUtf8(":/app/Resources/Add.png")));
trayIcon->show();
connect(trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
this, SLOT(iconActivated(QSystemTrayIcon::ActivationReason)));
...
}
void app::createActions()
{
minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void HSM::createTrayIcon()
{
trayIconMenu = new QMenu(this);
trayIconMenu->addAction(minimizeAction);
trayIconMenu->addAction(restoreAction);
trayIconMenu->addSeparator();
trayIconMenu->addAction(quitAction);
trayIcon = new QSystemTrayIcon(this);
trayIcon->setContextMenu(trayIconMenu);
trayIcon->setToolTip(tr("My app"));
}
void app::createActions()
{
minimizeAction = new QAction(tr("Mi&nimize"), this);
connect(minimizeAction, SIGNAL(triggered()), this, SLOT(hide()));
restoreAction = new QAction(tr("&Restore"), this);
connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));
quitAction = new QAction(tr("&Quit"), this);
connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));
}
void app::showMessage()
{
QSystemTrayIcon::MessageIcon icon = QSystemTrayIcon::MessageIcon();
trayIcon->showMessage(tr("My app"), tr("Some msg"), icon, 100);
}
void app::iconActivated(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
show();
break;
case QSystemTrayIcon::DoubleClick:
show();
break;
case QSystemTrayIcon::MiddleClick:
showMessage();
break;
default:
;
}
}
To copy to clipboard, switch view to plain text mode
Bookmarks