Qt加载托盘图标

Qt加载托盘图标

需要加载托盘图标时:

    QIcon icon(":/img/res/music.png");
    QSystemTrayIcon * systemTray = new QSystemTrayIcon(this);
    systemTray->setIcon(icon);
    systemTray->setToolTip("双击打开");
    systemTray->show();                    //显示托盘图标
    //关联托盘信号
   connect(systemTray,SIGNAL(activated(QSystemTrayIcon::ActivationReason)),this,SLOT(tray_notify(QSystemTrayIcon::ActivationReason)));

托盘信号的槽函数:

void TestWidget::tray_notify(const QSystemTrayIcon::ActivationReason & reason)
{
    switch(reason)
    {
    case QSystemTrayIcon::Context:        //右键
        qDebug()<<"QSystemTrayIcon::Context";
        break;
    case QSystemTrayIcon::DoubleClick:     //双击
        systemTray->hide();                //隐藏托盘
        qDebug()<<"QSystemTrayIcon::DoubleClick";
        break;
    case QSystemTrayIcon::Trigger:          //单击
        qDebug()<<"QSystemTrayIcon::Trigger";
        break;
    case QSystemTrayIcon::MiddleClick:      //中键单击
        qDebug()<<"QSystemTrayIcon::MiddleClick";
    default:                                        
        qDebug()<<"QSystemTrayIcon::Unknow";
        break;
    }
}

你可能感兴趣的:(QT)