其他分享
首页 > 其他分享> > Qt托盘图标最简示例

Qt托盘图标最简示例

作者:互联网

#include <QMenu>
#include <QSystemTrayIcon>

// 在 MainWindow 构造函数中
//菜单
QMenu *pTrayMenu = new QMenu(this);
pTrayMenu->addAction("Show",this,[](){ qDebug() << "Hello"; });

//图标
QSystemTrayIcon* pSystemTray = new QSystemTrayIcon(this);
pSystemTray->setIcon(QIcon(":/resource/img/logo.ico"));
pSystemTray->setContextMenu(pTrayMenu);

//显示
pSystemTray->show();

//发送桌面通知
pSystemTray->showMessage("标题", "内容");

  

标签:最简,Qt,示例,QMenu,pSystemTray,include,pTrayMenu,构造函数
来源: https://www.cnblogs.com/winterreisender/p/15697058.html