QT使用通知区域小图标

  1. QSystemTrayIcon *TrayIcon= new QSystemTrayIcon(this);  
  2. TrayIcon->setIcon(QIcon(":/icon/normal.png"));  
  3. connect(TrayIcon,SIGNAL(messageClicked()),this,SLOT(showNormal()));  
  4. restoreAction = new QAction(ctr("打开主界面"), this);  
  5. connect(restoreAction, SIGNAL(triggered()), this, SLOT(showNormal()));  
  6. saveAction = new QAction(ctr("保存配置"), this);  
  7. connect(saveAction, SIGNAL(triggered()), this, SLOT(saveconf()));  
  8. quitAction = new QAction(ctr("退出"), this);  
  9. connect(quitAction, SIGNAL(triggered()), qApp, SLOT(quit()));  
  10. / connect(ui->pushButton_4,SIGNAL(clicked()),this,SLOT(saveconf()));  
  11. connect(TrayIcon,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(iconActivated(QSystemTrayIcon::ActivationReason))); //触发信号  
  12. QMenu *trayIconMenu = new QMenu(this);  
  13.   
  14. trayIconMenu->addAction(restoreAction);  
  15. trayIconMenu->addAction(saveAction);  
  16. trayIconMenu->addSeparator();  
  17. trayIconMenu->addAction(quitAction);  
  18. TrayIcon->setContextMenu(trayIconMenu); //添加右键菜单  
  19.         TrayIcon->show();  

 

左键单击触发槽

[cpp]  view plain  copy
  1. void MainWindow::iconActivated(QSystemTrayIcon::ActivationReason reason)  
  2. {  
  3.     switch (reason) {  
  4.          case QSystemTrayIcon::Trigger:  
  5.             this->showNormal();  
  6.             break;  
  7.          default:  
  8.              ;  
  9.          }  
  10.   

你可能感兴趣的:(QT使用通知区域小图标)