QT中显示右下角托盘图标

QT中显示托盘图标使用QSystemTrayIcon类:

    m_trayIcon = new QSystemTrayIcon(this);           
    m_trayIcon->setIcon(QIcon(":/image/myico.ico"));     //设置图标
    m_trayIcon->setToolTip(tr("Known image viewer"));    //设置鼠标放上去显示的信息
    QMenu *menu = new QMenu(this);			 //右键菜单
    menu->addAction(ui->action_O);                       //这几个action是在设计师下添加的
    menu->addAction(ui->action_P);
    menu->addAction(ui->action_N);
    menu->addAction(ui->action_L);
    menu->addAction(ui->action_R);
    menu->addAction(ui->action);
    menu->addAction(ui->action_Q);
    m_trayIcon->setContextMenu(menu); 			 //设置右键菜单
    connect(m_trayIcon, SIGNAL(activated(QSystemTrayIcon::ActivationReason)),
            this, SLOT(slotIconActivated(QSystemTrayIcon::ActivationReason)));
    m_trayIcon->show();					 //显示
 
  
 
  
void ImageDisplay::slotIconActivated(QSystemTrayIcon::ActivationReason reason)
{
    switch(reason)
    {
    case QSystemTrayIcon::Trigger :
        setWindowState(Qt::WindowActive);
        activateWindow();
        break;
    default:
        break;
    }
}
 
  

你可能感兴趣的:(qt,menu,类)