QSystemTrayIcon* m_TrayIcon;
m_TrayIcon=new QSystemTrayIcon(this);
connect(m_TrayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason)));
void QtHttpServer::changeEvent(QEvent *event)
{
if((event->type()==QEvent::WindowStateChange)&&isMinimized())
{
hide();
m_TrayIcon->showMessage("SystemTrayIcon",QObject::trUtf8("程序最小化到托盘"),QSystemTrayIcon::Information,10000);
event->ignore();
}
}
void QtHttpServer::on_ShowMainAction()
{
this->show();
}
void QtHttpServer::on_ExitAppAction()
{
exit(0);
}
void QtHttpServer::on_activatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
switch(reason){
case QSystemTrayIcon::Trigger:
//单击托盘图标
this->showNormal();
break;
case QSystemTrayIcon::DoubleClick:
//双击托盘图标
//双击后显示主程序窗口
this->showNormal();
break;
default:
break;
}
}