#include "QtWidgetsApplication1.h"
#include <QSystemTrayIcon>
#include <QMenu>
#include <QIcon>
QtWidgetsApplication1::QtWidgetsApplication1(QWidget *parent)
: QDialog(parent)
{
ui.setupUi(this);
QMenu *m = new QMenu(this);
QIcon icon(u8":/Resouce/托盘.png");
m_pSystemTray = new QSystemTrayIcon(this);
m_pSystemTray->setIcon(icon);
m_pSystemTray->setToolTip(u8"托盘测试");
m_pMinimumAct = new QAction(u8"最小化", this);
connect(m_pMinimumAct, SIGNAL(triggered()), this, SLOT(hide()));
m_pMaximumAct = new QAction(u8"最大化", this);
connect(m_pMaximumAct, SIGNAL(triggered()), this, SLOT(showMaximized()));
m_pRestoreAct = new QAction(u8"恢复窗口", this);
connect(m_pRestoreAct, SIGNAL(triggered()), this, SLOT(showNormal()));
m_pQuitAct = new QAction(u8"退出", this);
connect(m_pQuitAct, SIGNAL(triggered()), qApp, SLOT(quit()));
connect(m_pSystemTray, SIGNAL(activated(QSystemTrayIcon::ActivationReason)), this, SLOT(slotActivatedSysTrayIcon(QSystemTrayIcon::ActivationReason)));
QMenu *pContextMenu = new QMenu(this);
pContextMenu->addAction(m_pMinimumAct);
pContextMenu->addAction(m_pMaximumAct);
pContextMenu->addAction(m_pRestoreAct);
pContextMenu->addSeparator();
pContextMenu->addAction(m_pQuitAct);
m_pSystemTray->setContextMenu(pContextMenu);
m_pSystemTray->show();
close();
}
void QtWidgetsApplication1::closeEvent(QCloseEvent *event)
{
if (m_pSystemTray->isVisible())
{
hide();
m_pSystemTray->showMessage(u8"托盘", u8"该程序托盘正在运行!");
}
}
void QtWidgetsApplication1::slotActivatedSysTrayIcon(QSystemTrayIcon::ActivationReason reason)
{
switch (reason)
{
case QSystemTrayIcon::Trigger:
//单击托盘图标
break;
case QSystemTrayIcon::DoubleClick:
//双击托盘图标
//双击后显示主程序窗口
this->show();
break;
default:
break;
}
}
QT-托盘使用,一看就懂
版权申诉
1星 65 浏览量
2023-03-14
13:40:55
上传
评论
收藏 6KB RAR 举报
进击的大海贼
- 粉丝: 1w+
- 资源: 196
最新资源
- ISOSAE21434.D1-2020SAE美国汽车标准
- 奥比中光RGBD在JETSON ORIN NX的ROS程序
- SerialNumberUtil.java
- autojspro写的木鱼小软件,模拟木鱼的敲击声,提供源代码
- 修改windows服务器远程桌面端口批处理
- 黑马Java八股文面试题视频教程,Java面试八股文宝典(含阿里、腾迅大厂java面试真题,java数据结构,java并发
- java调用科大讯飞在线语音合成API -完整代码
- Python爬虫基础知识.zip
- Java八股文和面试项目介绍-春招秋招校招社招
- 其他类别JSP网页HTML编辑器 v1.0 beat-jsphtmleditor.7z
资源上传下载、课程学习等过程中有任何疑问或建议,欢迎提出宝贵意见哦~我们会及时处理!
点击此处反馈