QT 范例阅读:系统托盘 The System Tray Icon example

main.cpp

    QApplication app(argc, argv);//判断系统是否支持 系统托盘功能if (!QSystemTrayIcon::isSystemTrayAvailable()) {QMessageBox::critical(0, QObject::tr("Systray"),QObject::tr("I couldn't detect any system tray ""on this system."));return 1;}//关闭 隐式退出在最后一个窗口关闭时(这个示例该行语句注释也没区别)QApplication::setQuitOnLastWindowClosed(false);

windows.h

protected://重载关闭事件void closeEvent(QCloseEvent *event) override;private slots://点击托盘图标时的处理void iconActivated(QSystemTrayIcon::ActivationReason reason);//显示托盘弹出消息void showMessage();//点击托盘消息后的处理void messageClicked();private:   //托盘图标右键 菜单动作QAction *minimizeAction;QAction *maximizeAction;QAction *restoreAction;QAction *quitAction;//系统托盘QSystemTrayIcon *trayIcon;//托盘菜单QMenu *trayIconMenu;
void Window::createActions()
{minimizeAction = new QAction(tr("Mi&nimize"), this);connect(minimizeAction, &QAction::triggered, this, &QWidget::hide);maximizeAction = new QAction(tr("Ma&ximize"), this);connect(maximizeAction, &QAction::triggered, this, &QWidget::showMaximized);restoreAction = new QAction(tr("&Restore"), this);connect(restoreAction, &QAction::triggered, this, &QWidget::showNormal);quitAction = new QAction(tr("&Quit"), this);connect(quitAction, &QAction::triggered, qApp, &QCoreApplication::quit);
}void Window::createTrayIcon()
{trayIconMenu = new QMenu(this);trayIconMenu->addAction(minimizeAction);trayIconMenu->addAction(maximizeAction);trayIconMenu->addAction(restoreAction);trayIconMenu->addSeparator();trayIconMenu->addAction(quitAction);trayIcon = new QSystemTrayIcon(this);trayIcon->setContextMenu(trayIconMenu);
}//是否显示托盘图标connect(showIconCheckBox, &QAbstractButton::toggled, trayIcon, &QSystemTrayIcon::setVisible);//托盘消息点击事件    connect(trayIcon, &QSystemTrayIcon::messageClicked, this, &Window::messageClicked);//托盘图标点击事件connect(trayIcon, &QSystemTrayIcon::activated, this, &Window::iconActivated);void Window::closeEvent(QCloseEvent *event)
{//如果显示了托盘,关闭事件忽略,窗体隐藏if (trayIcon->isVisible()) {QMessageBox::information(this, tr("Systray"),tr("The program will keep running in the ""system tray. To terminate the program, ""choose <b>Quit</b> in the context menu ""of the system tray entry."));hide();event->ignore();}
}//托盘图标点击消息处理
void Window::iconActivated(QSystemTrayIcon::ActivationReason reason)
{switch (reason) {case QSystemTrayIcon::Trigger:case QSystemTrayIcon::DoubleClick: //改变图标iconComboBox->setCurrentIndex((iconComboBox->currentIndex() + 1) % iconComboBox->count());break;case QSystemTrayIcon::MiddleClick:showMessage();break;default:;}
}//显示消息
void Window::showMessage()
{showIconCheckBox->setChecked(true);QSystemTrayIcon::MessageIcon msgIcon = QSystemTrayIcon::MessageIcon(typeComboBox->itemData(typeComboBox->currentIndex()).toInt());if (msgIcon == QSystemTrayIcon::NoIcon) {QIcon icon(iconComboBox->itemIcon(iconComboBox->currentIndex()));trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), icon,durationSpinBox->value() * 1000);} else {trayIcon->showMessage(titleEdit->text(), bodyEdit->toPlainText(), msgIcon,durationSpinBox->value() * 1000);}
}

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/668229.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

利用jmeter完成简单的压力测试

Jmeter是一个非常好用的压力测试工具。Jmeter用来做轻量级的压力测试&#xff0c;非常合适&#xff0c;只需要十几分钟&#xff0c;就能把压力测试需要的脚本写好。 1、什么是压力测试 顾名思义&#xff1a;压力测试&#xff0c;就是 被测试的系统&#xff0c;在一定的访问压…

下载、安装Jenkins

进入官网 下载Jenkins https://www.jenkins.io 直接点击Download 一般是下长期支持版 因为它是java写的&#xff0c;你要运行它&#xff08;Jenkins.war&#xff09;肯定要有java环境 有两种方式去运行它&#xff0c;一种是下载Tomcat&#xff08;是很经典的java容器或者jav…

代码随想录day16 Java版 二叉树部分

404.左叶子之和 感觉就是遍历&#xff0c;遇到叶子结点就累加&#xff0c;试了下居然过了 class Solution {int sum 0;public int sumOfLeftLeaves(TreeNode root) {add(root);return sum;}void add(TreeNode root){if (root null) return;if (root.left ! null &&…

linux编译ffmpeg动态库

1&#xff0c;获取源码&#xff1a;git clone https://git.ffmpeg.org/ffmpeg.git 2&#xff0c;创建编译目录&#xff0c;并编译、安装&#xff0c; cd ffmpeg mkdir build cd build ../configure --prefix~/ffmpeg --enable-shared --enable-debug1 //configure后需要使…

深入探索C++ Move语义:现代编程中的性能革命

1. 引言 介绍C中的Move语义 Move语义是C11中引入的一个重要特性&#xff0c;它为C编程语言带来了显著的性能改进。在这之前&#xff0c;C只支持拷贝语义&#xff0c;即通过拷贝构造函数和拷贝赋值操作符来复制对象。Move语义通过允许"移动"而非"拷贝"资源…

Git版本管理工具(基础):这一篇基本能满足Git基本的使用需求了!

文章目录 Git01-什么是Git作用 02-使用Git03-Git仓库创建 04-Git的三个区域三个区域 05-Git文件状态06-Git暂存区使用07-Git回退版本08-删除文件 Git 01-什么是Git 答&#xff1a;他是一个免费开源的&#xff0c;分布式代码版本控制系统&#xff0c;帮助开发团队维护代码 作用…

三、消除分心的事物(Eliminating Distractions)

External Improvements 外部改进 1.Eliminating Distractions 一、消除分心的事物 Distractions are the most obvious problem when it comes to focus, and they are often the easiest to fix. In particular, you want to find an environment for focus that minimizes b…

爬虫工作量由小到大的思维转变---<第四十五章 Scrapyd 关于gerapy遇到问题>

前言: 本章主要是解决一些gerapy遇到的问题,会持续更新这篇! 正文: 问题1: 1400 - build.py - gerapy.server.core.build - 78 - build - error occurred (1, [E:\\项目文件名\\venv\\Scripts\\python.exe, setup.py, clean, -a, bdist_uberegg, -d, C:\\Users\\Administrat…

网络安全面试题收集

1 Web篇 1.1 什么是SQL注入攻击&#xff1f;如何防止SQL注入攻击&#xff1f; SQL注入攻击是指攻击者通过向Web应用程序的输入框中插入恶意SQL语句来执行未经授权的操作。防止SQL注入攻击的方法包括使用参数化查询和输入验证&#xff0c;以及避免使用动态SQL语句。 1.2 什么…

红队渗透靶机:TIKI: 1

目录 信息收集 1、arp 2、nmap 3、nikto 4、whatweb 目录探测 1、dirsearch 2、gobuster WEB web信息收集 searchsploit cms信息收集 ssh登录 提权 信息收集 1、arp ┌──(root㉿ru)-[~/kali] └─# arp-scan -l Interface: eth0, type: EN10MB, MAC: 00:0c:2…

数据结构-数组

1.容器 容器用于容纳元素集合&#xff0c;并对元素集合进行管理和维护&#xff0e; 传统意义上的管理和维护就是&#xff1a;增&#xff0c;删&#xff0c;改&#xff0c;查&#xff0e; 我们分析每种类型容器时&#xff0c;主要分析其增&#xff0c;删&#xff0c;改&#xf…

Matlab 移动最小二乘求解仿射变换

文章目录 一、简介二、实现代码三、实现效果参考文献一、简介 在现实生活中,我们常常应用一些刚性的变换来实现物体的旋转平移,对于非刚性的变换我们都没有在意,其实这种变换也是无处不在的,如我们经常看的动画就可以通过一些非刚性的变换达到一些非常夸张的效果。这里,我…

iMazing 3中文版双平台版本同步,iOS 设备在 Windows 上也能自动备份了

自从WWDC 2019 宣布 iTunes 退役后&#xff0c;也许很多小伙伴都对「上位者」iMazing 有所耳闻。 这款设计更加人性化、功能细致强大的 iOS 备份管理工具。 iMazing 支持在 Windows 及 Mac 上运行&#xff0c;而这个月 Windows 版本更新至 2.17. 之后&#xff0c;iMazing 的双…

Kubernetes基础(十一)-CNI网络插件用法和对比

1 CNI概述 1.1 什么是CNI&#xff1f; Kubernetes 本身并没有实现自己的容器网络&#xff0c;而是借助 CNI 标准&#xff0c;通过插件化的方式来集成各种网络插件&#xff0c;实现集群内部网络相互通信。 CNI&#xff08;Container Network Interface&#xff0c;容器网络的…

如何构建起自己的伦敦银交易系统?

投资者在市场这个江湖中行走&#xff0c;就需要有一技防身&#xff0c;不然很容易会被市场的风险所淹没&#xff0c;这个“一技”指的就是伦敦银交易系统。如果投资者要构建起自己的伦敦银交易系统&#xff0c;应该从哪几个方面着手呢&#xff1f;下面我们就来讨论一下。 分析方…

103 C++ 内存高级话题 重载全局new,delete,定位new以及重载等

一 重载全局 operator new 和 operator delete 操作符 前面是看到了 我们在某一个类中 重写了 operator new 和 operator delete。 实际上也可以 重载全局的 operator new 和 operator delete。 重载了全局的 operator new 和 operator delete 会对整个.cpp中的所有其作用&a…

Jenkins(本地Windows上搭建)上传 Pipeline构建前端项目并将生成dist文件夹上传至指定服务器

下载安装jdk https://www.oracle.com/cn/java/technologies/downloads/#jdk21-windows 下载jenkins window版 双击安装 https://www.jenkins.io/download/thank-you-downloading-windows-installer-stable/ 网页输入 http://localhost:8088/ 输入密码、设置账号、安装推…

2024-2-4-复习作业

源代码&#xff1a; #include <stdio.h> #include <stdlib.h> typedef int datatype; typedef struct Node {datatype data;struct Node *next;struct Node *prev; }*DoubleLinkList;DoubleLinkList create() {DoubleLinkList s(DoubleLinkList)malloc(sizeof(st…

「连载」边缘计算(十三)02-01:边缘部分源码(源码分析篇)

&#xff08;接上篇&#xff09; 配置模块初始化 配置模块初始化具体如下所示。 err : archaius.Init() ... CONFIG archaius.GetConfigFactory() &#xff08;3&#xff09; 获取内存配置源 获取内存配置源具体如下所示。 ms : memoryconfigsource.NewMemoryConfigurati…

小程序配置服务器域名

配置小程序的服务器域名是一个重要的步骤&#xff0c;因为它关系到小程序能否正常访问后端服务。在微信小程序中&#xff0c;出于安全考虑&#xff0c;所有的网络请求都需要在小程序管理后台进行域名配置&#xff0c;只有配置过的域名才可以被小程序访问。 步骤概述 获取服务器…