Qt创建系统托盘菜单
createMenu();
if(!QSystemTrayIcon::isSystemTrayAvailable())
{
return;
}
myTrayIcon = new QSystemTrayIcon(this);
myTrayIcon->setIcon(QIcon(":/new/prefix1/ico"));
myTrayIcon->setToolTip("Qt托盘图标功能");
myTrayIcon->showMessage("托盘","托盘管理",QSystemTrayIcon::Information,10000);
myTrayIcon->setContextMenu(myMenu);
myTrayIcon->show();
void MainWindow::createMenu()
{
restoreWinAction = new QAction("恢复(&R)",this);
quitAction = new QAction("退出(&Q)",this);
connect(restoreWinAction,SIGNAL(triggered()),this,SLOT(showNormal()));
connect(quitAction,SIGNAL(triggered()),qApp,SLOT(quit()));
myMenu = new QMenu((QWidget*)QApplication::desktop());
myMenu->addAction(restoreWinAction);
myMenu->addSeparator();
myMenu->addAction(quitAction);
}
void MainWindow::showNormal()
{
this->show();
}
void QWidget:: changeEvent (QEvent *e)
{
if((e->type()==QEvent::WindowStateChange)&&this->isMinimized())
{
this->hide();
}
}