当前位置:网站首页>Qt创建应用程序托盘及相关功能
Qt创建应用程序托盘及相关功能
2022-07-24 10:32:00 【我啥都会】
头文件:
QSystemTrayIcon *tray;//托盘图标
QMenu *menu;//托盘菜单
QAction *reset;//恢复窗口
QAction *quit;//退出程序初始化托盘函数:
void MainWindow::initTray()
{
tray = new QSystemTrayIcon(this);
tray->setIcon(QIcon(QPixmap(":/images/icon.ico")));
connect(tray, &QSystemTrayIcon::activated, this, &MainWindow::onTrayClicked);
menu = new QMenu(this);
reset = new QAction(this);
reset->setText("显示窗口");
reset->setIcon(QIcon(":/images/show.png"));
connect(reset, &QAction::triggered, this, &MainWindow::showNormal);
quit = new QAction( this);
quit->setText("退出程序");
quit->setIcon(QIcon(":/images/quit.png"));
connect(quit, &QAction::triggered, qApp, &QCoreApplication::quit);
tray->setContextMenu(menu);
menu->addAction(reset);
menu->addAction(quit);
}重写关闭事件:
void MainWindow::closeEvent(QCloseEvent *event)
{
event->ignore();
this->hide();
tray->show();
}单击托盘图标槽函数:
void MainWindow::onTrayClicked(QSystemTrayIcon::ActivationReason reason)
{
if ( reason == QSystemTrayIcon::Trigger )
{
this->showNormal();
}
}问题:
如果最小化到托盘的过程中有msgbox弹出,会导致整个程序退出。解决办法:

效果:
边栏推荐
- MySQL - full text index
- [sword finger offer II 115. reconstruction sequence]
- Sub query of multi table query_ Single row and single column
- MySQL - unique index
- 谷歌联合高校研发通用模型ProteoGAN,可设计生成具有新功能的蛋白质
- Segment tree--
- 给你的网站加一个爱发电角标
- Is it safe to open an online stock account?
- ECCV 2022 | Tsinghua proposes the first transformer to embed spectral sparsity
- Will not be rejected! Learn the distributed architecture notes sorted out by Alibaba Daniel in 35 days, with a salary increase of 20K
猜你喜欢

Sentinel flow control quick start

Adobe Substance 3D Designer 2021软件安装包下载及安装教程

MySQL - lock

数组元素移除问题

MySQL——锁

MySQL - full text index

Sentinel three flow control effects

What did zoneawareloadbalancer of ribbon and its parent class do?
![[correcting Hongming] what? I forgot to take the](/img/41/c8fa6380ab63949ae6d904fdbb005c.png)
[correcting Hongming] what? I forgot to take the "math required course"!

WEB安全基础 - - -文件上传(文件上传绕过)
随机推荐
MySQL - 全文索引
Ffmpeg splash screen solution (modify the source code and discard incomplete frames)
2022, enterprise informatization construction based on Unified Process Platform refers to thubierv0.1
Arduino + AD9833 波形发生器
The method modified by private can be accessed through reflection. What is the meaning of private?
Binary original code, inverse code, complement code
Partition data 1
Design of dual machine hot standby scheme
脚手架文件目录说明、文件暴露
How does ribbon get the default zoneawareloadbalancer?
Image processing: floating point number to fixed point number
MySQL——锁
Kotlin Advanced Grammar
Sentinel 实现 pull 模式规则持久化
Sentinel three flow control modes
每日三题 7.22
Analysis of distributed lock redistribution principle
分布式事务处理方案大 PK!
What is NFT? How to develop NFT system?
Mysql database JDBC programming