河南专业网站建设招聘/seo免费优化工具
文章目录
- 一.QMessageBox介绍
- 枚举
- 属性
- 函数
- 二.QMessageBox的用法
- 1.导入QMessage库
- 2.弹窗提示
- 3.提供选项的弹窗提示
- 4.作为提示,报警,报错提示窗口
一.QMessageBox介绍
文本消息显示框(message box)向用户发出情况警报信息并进一步解释警报或向用户提问,以及可选的详细文本以在用户请求时提供更多数据。
枚举
枚举 | 枚举值 |
---|---|
enum | ButtonRole { InvalidRole, AcceptRole, RejectRole, DestructiveRole, ActionRole, …, ResetRole } |
enum | Icon { NoIcon, Question, Information, Warning, Critical } |
enum | StandardButton { Ok, Open, Save, Cancel, Close, …, ButtonMask } |
flags | StandardButtons |
属性
属性名称 | 类型 |
---|---|
detailedText | QString |
standardButtons | StandardButtons |
icon | Icon |
iconPixmap | QPixmap |
informativeText | QString |
text | QString |
textFormat | Qt::TextFormat |
textInteractionFlags | Qt::TextInteractionFlags |
函数
返回值 | 函数原型 | 说明 |
---|---|---|
QMessageBox(QMessageBox::Icon icon, const QString &title, const QString &text, QMessageBox::StandardButtons buttons = NoButton, QWidget *parent = nullptr, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint) | |
QMessageBox(QWidget *parent = nullptr) | 构造函数 | |
virtual | ~QMessageBox() | 析构函数 |
void | addButton(QAbstractButton *button, QMessageBox::ButtonRole role) | 添加按钮到消息框中 |
QPushButton * | addButton(const QString &text, QMessageBox::ButtonRole role) | 添加按钮到消息框中 |
QPushButton * | addButton(QMessageBox::StandardButton button) | 添加按钮到消息框中 |
QAbstractButton * | button(QMessageBox::StandardButton which) const | 返回与标准按钮对应的指针,如果此消息框中不存在标准按钮,则返回nullptr |
QMessageBox::ButtonRole | buttonRole(QAbstractButton *button) const | 返回指定按钮的按钮角色。如果按钮为nullptr或尚未添加到消息框,则此函数返回InvalidRole。 |
QList<QAbstractButton *> | buttons() const | 返回已添加到消息框中的所有按钮的列表。 |
QCheckBox * | checkBox() const | 返回对话框上显示的复选框。如果未设置任何复选框,则为nullptr。 |
QAbstractButton * | clickedButton() const | 返回用户单击的按钮,如果用户按Esc键且未设置转义按钮,则返回nullptr。 |
QPushButton * | defaultButton() const | 返回应该是消息框默认按钮的按钮。如果未设置默认按钮,则返回nullptr。 |
QString | detailedText() const | 保存要显示在详细信息区域中的文本。 |
QAbstractButton * | escapeButton() const | 返回按下转义时激活的按钮。 |
QMessageBox::Icon | icon() const | 保存消息框的图标 |
QPixmap | iconPixmap() const | 保存当前图标 |
QString | informativeText() const | 包含为消息提供更完整描述的信息性文本 |
void | open(QObject *receiver, const char *member) | 打开对话框并将其 finished()或 buttonClicked()信号连接到接收器和成员指定的插槽。如果slot-in成员的第一个参数有一个指针,则连接到 buttonClicked(),否则连接到finished()。 |
void | removeButton(QAbstractButton *button) | 从按钮框中删除按钮而不删除它。 |
void | setCheckBox(QCheckBox *cb) | 设置消息对话框上的复选框cb。消息框获取复选框的所有权。参数cb可以是nullptr,以从消息框中删除现有复选框。 |
void | setDefaultButton(QPushButton *button) | 将消息框的默认按钮设置为按钮。 |
void | setDefaultButton(QMessageBox::StandardButton button) | 将消息框的默认按钮设置为按钮。 |
void | setDetailedText(const QString &text) | 保存要显示在详细信息区域中的文本。 |
void | setEscapeButton(QAbstractButton *button) | 将按下Escape键时激活的按钮设置为按钮。 |
void | setEscapeButton(QMessageBox::StandardButton button) | 将按下Escape键时激活的按钮设置为按钮。 |
void | setIcon(QMessageBox::Icon) | 保存消息框的图标 |
void | setIconPixmap(const QPixmap &pixmap) | 保存消息框的图标 |
void | setInformativeText(const QString &text) | 保存要显示的消息框文本 |
void | setStandardButtons(QMessageBox::StandardButtons buttons) | 根据文本格式设置(QMessageBox::textFormat),文本将被解释为纯文本或富文本。默认设置为 Qt::AutoText,,即消息框将尝试自动检测文本的格式。 |
void | setText(const QString &text) | 保存要显示的消息框文本 |
void | setTextFormat(Qt::TextFormat format) | 保存消息框显示的文本格式 |
void | setTextInteractionFlags(Qt::TextInteractionFlags flags) | |
void | setWindowModality(Qt::WindowModality windowModality) | |
void | setWindowTitle(const QString &title) | |
QMessageBox::StandardButton | standardButton(QAbstractButton *button) const | 返回与给定按钮对应的标准按钮枚举值,如果给定按钮不是标准按钮,则返回NoButton。 |
QMessageBox::StandardButtons | standardButtons() const | 返回与给定按钮对应的标准按钮枚举值,如果给定按钮不是标准按钮,则返回NoButton。 |
QString | text() const | 保存要显示的消息框文本 |
Qt::TextFormat | textFormat() const | 保存消息框显示的文本格式 |
Qt::TextInteractionFlags | textInteractionFlags() const |
二.QMessageBox的用法
1.导入QMessage库
#include <QMessageBox>
2.弹窗提示
构造QMessageBox的实例,设置所需显示的消息,然后调用exec()
来显示消息。用户必须单击“确定”按钮以关闭消息框。GUI的其余部分将被阻止,直到消息框被关闭。
QMessageBox msgBox;
msgBox.setText(u8"你好~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~");
msgBox.exec();
3.提供选项的弹窗提示
一个比仅仅提醒用户事件更好的方法是询问用户该怎么做。将问题存储在信息性文本属性中,并将标准按钮属性设置为所需的按钮集作为用户响应集。通过使用位或运算符组合StandardButtons
中的值来指定按钮。按钮的显示顺序取决于平台。例如,在Windows上,“保存”显示在“取消”的左侧,而在Mac OS上,顺序相反。要向用户提供更多信息以帮助他回答问题,通过setDetailedText
设置详细文本属性。如果设置了详细文本属性,则显示详细信息按钮。exec()
槽返回单击的按钮的StandardButtons
值。
QMessageBox msgBox;
msgBox.setText(u8"该文档已被修改.");
msgBox.setDetailedText(u8"这里是详细的提示信息");
msgBox.setInformativeText(u8"是否要保存你的修改?");
msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
msgBox.setDefaultButton(QMessageBox::Save);
int ret = msgBox.exec();switch (ret) {case QMessageBox::Save:qDebug() << "save";break;case QMessageBox::Discard:qDebug() << "Discard";break;case QMessageBox::Cancel:qDebug() << "Cancel";break;default:qDebug() << "default";break;
}
4.作为提示,报警,报错提示窗口
int ret = QMessageBox::information(this, tr(u8"信息提示"),tr(u8"该文档已被修改.\n"u8"是否要保存你的修改?"),QMessageBox::Ok | QMessageBox::Cancel | QMessageBox::Help);
对于窗口的类型,有以下几种可以选择:
内容 | 值 | 说明 |
---|---|---|
QMessageBox::NoIcon | 0 | the message box does not have any icon. |
QMessageBox::Question | 4 | an icon indicating that the message is asking a question. |
QMessageBox::Information | 1 | an icon indicating that the message is nothing out of the ordinary. |
QMessageBox::Warning | 2 | an icon indicating that the message is a warning, but can be dealt with. |
QMessageBox::Critical | 3 | an icon indicating that the message represents a critical problem. |
对于窗口中的按钮,有以下几种可以选择:
内容 | 值 | 说明 |
---|---|---|
QMessageBox::Ok | 0x00000400 | An “OK” button defined with the AcceptRole. |
QMessageBox::Open | 0x00002000 | An “Open” button defined with the AcceptRole. |
QMessageBox::Save | 0x00000800 | A “Save” button defined with the AcceptRole. |
QMessageBox::Cancel | 0x00400000 | A “Cancel” button defined with the RejectRole. |
QMessageBox::Close | 0x00200000 | A “Close” button defined with the RejectRole. |
QMessageBox::Discard | 0x00800000 | A “Discard” or “Don’t Save” button, depending on the platform, defined with the DestructiveRole. |
QMessageBox::Apply | 0x02000000 | An “Apply” button defined with the ApplyRole. |
QMessageBox::Reset | 0x04000000 | A “Reset” button defined with the ResetRole. |
QMessageBox::RestoreDefaults | 0x08000000 | A “Restore Defaults” button defined with the ResetRole. |
QMessageBox::Help | 0x01000000 | A “Help” button defined with the HelpRole. |
QMessageBox::SaveAll | 0x00001000 | A “Save All” button defined with the AcceptRole. |
QMessageBox::Yes | 0x00004000 | A “Yes” button defined with the YesRole. |
QMessageBox::YesToAll | 0x00008000 | A “Yes to All” button defined with the YesRole. |
QMessageBox::No | 0x00010000 | A “No” button defined with the NoRole. |
QMessageBox::NoToAll | 0x00020000 | A “No to All” button defined with the NoRole. |
QMessageBox::Abort | 0x00040000 | An “Abort” button defined with the RejectRole. |
QMessageBox::Retry | 0x00080000 | A “Retry” button defined with the AcceptRole. |
QMessageBox::Ignore | 0x00100000 | An “Ignore” button defined with the AcceptRole. |
QMessageBox::NoButton | 0x00000000 | An invalid button. |
相关文章:

Qt QMessageBox详解
文章目录一.QMessageBox介绍枚举属性函数二.QMessageBox的用法1.导入QMessage库2.弹窗提示3.提供选项的弹窗提示4.作为提示,报警,报错提示窗口一.QMessageBox介绍 文本消息显示框(message box)向用户发出情况警报信息并进一步解释警报或向用户提问&…...

Flutter之beamer路由入门指南
beamer路由入门指南 前言使用方法1、路由配置方式1路由配置方式2路由跳转测试现象前言 Beamer是一个很好用的路由组件,本文以beamer1.5.0版本进行说明,前面博主也介绍了其他路由组件 Flutter实战之go_router路由组件入门指南 、 Flutter之Fluro路由组件入门指南 Flutter之Ge…...

「基础篇」机器学习概览
文章目录1. 什么是机器学习2. 引入机器学习3. 应用场景4. 机器学习分类4.1. 有无人类监督4.2. 是否增量学习4.3. 泛化方式5. 主要挑战6. 测试与验证1. 什么是机器学习 机器学习(Machine Learning,ML)是一个研究领域,让计算机无需…...

揭秘可视化图探索工具 NebulaGraph Explore 是如何实现图计算的
前言 在可视化图探索工具 NebulaGraph Explorer 3.1.0 版本中加入了图计算工作流功能,针对 NebulaGraph 提供了图计算的能力,同时可以利用工作流的 nGQL 运行能力支持简单的数据读取,过滤及写入等数据处理功能。 本文将简单分享下 NebulaGr…...

移动架构43_什么是Jetpack
Android移动架构汇总 文章目录一 Android 开发框架演变1 MVC2 MVP3 MVVM二 什么是JetPack三 如何构建支持Jetpack项目一 Android 开发框架演变 1 MVC Model-View-Controller,模型-视图-控制器,Model负责数据管理,View负责UI显…...

TiDB的分布式事务原理探究
事务开启 获取全局授时作为startTS构建一个tikvTxn对象(包括snapshot)。 事务写 txn.Set方法本质上将kv值写入了一个内存缓存(即kv/memdb_buffer.go中的memDbBuffer)中。该内存kv数据库利用的是golevel提供的功能。 事务回滚 直接将tikvTxn的valid字段…...

【C语言】函数指针和指针函数
文章目录[TOC](文章目录)前言概述函数指针定义:使用:回调函数指针函数前言 今天学一下函数指针 提示:以下是本篇文章正文内容,下面案例可供参考 概述 函数指针:是一个指向函数的指针,在内存空间中存放的…...

Nodejs中npx简介和作用
一、npx简介npm从5.25.2版开始,增加了 npx 命令。方便了我在项目中使用全局包。二、安装Node安装后自带npm模块,可以直接使用npx命令。如果不能使用用,就要手动安装一下。npm install -g npx三、使用npx想要解决的主要问题,就是调…...

Matplotlib精品学习笔记001——绘制3D图形详解+实例讲解
3D图片更生动,或许在时间序列数据的展示上更胜一筹 想法: 学习3D绘图的想法来自科研绘图中。我从事的专业是古植物学,也就是和植物化石打交道。化石有三大信息:1.物种信息,也就是它的分类学价值;2.时间信息…...

学习ifconfig实战技巧,成为网络管理高手
文章目录前言一. ifconfig 命令介绍二. 语法格式及常用选项三. 参考案例3.1 显示网络设备信息3.2 启动和关闭指定的网卡3.3 对指定的网卡设备执行修改IP地址操作3.4 启动和关闭ARP协议3.5 使用ifconfig添加网卡总结前言 大家好,又见面了,我是沐风晓月&a…...

day38|70. 爬楼梯(进阶)、322. 零钱兑换、279.完全平方数
70. 爬楼梯(进阶) 假设你正在爬楼梯。需要 n 阶你才能到达楼顶。 每次你可以爬 1 或 2 个台阶。你有多少种不同的方法可以爬到楼顶呢? 示例 1: 输入:n 2 输出:2 解释:有两种方法可以爬到楼顶。 1. 1 阶 1 阶 2. 2…...

SpringBoot全局异常处理
一、目的 当客户端/前端向服务端发送一个请求后,这个请求并不是每次都能完全正确的处理,比如出现一些资源不存在、参数错误或者内部错误等信息的时候,就需要将异常反馈给客户端或者前端。那么这就需要程序有完整的异常处理机制。 在 Java 中所…...

SpringBoot异常处理
目录 一、 错误处理 1. 默认规则 2. 定制错误处理逻辑 二、自定义异常处理 1. 实现 ErrorController 2. RestControllerAdvice/ControllerAdvice ExceptionHandler 实现自定义异常 3. 新建 UserController.class 测试 3 种不同异常的处理 4. 最终效果如下 补充 1. 参…...

《C++ Primer Plus》(第6版)第8章编程练习
《C Primer Plus》(第6版)第8章编程练习《C Primer Plus》(第6版)第8章编程练习1. 打印字符串2. CandyBar3. 将string对象的内容转换为大写4. 设置并打印字符串5. max5()6. maxn()7. SumArray()《C Primer Plus》(第6版…...

RAD Studio 11.3 Alexandria Crack
RAD Studio 11.3 Alexandria Crack 瞄准最新平台版本-此版本增加了对Android 13和Apple macOS Ventura的官方支持。它还支持Ubuntu 22 LTS和Microsoft Windows Server 2022。 使用生物特征认证-New为FireMonkey移动应用程序提供了新的移动生物特征认证组件。 部署嵌入式InterBa…...

Stm32 iic 协议使用
/* 第1个参数为I2C操作句柄 第2个参数为从机设备地址 第3个参数为从机寄存器地址 第4个参数为从机寄存器地址长度 第5个参数为发送的数据的起始地址 第6个参数为传输数据的大小 第7个参数为操作超时时间 */ HAL_I2C_Mem_Write(&hi2c2,salve_add,0,0,PA_BUFF,sizeof(PA_BUFF…...

Malware Dev 02 - Windows SDDL 后门利用之 SCManager
写在最前 如果你是信息安全爱好者,如果你想考一些证书来提升自己的能力,那么欢迎大家来我的 Discord 频道 Northern Bay。邀请链接在这里: https://discord.gg/9XvvuFq9Wb我拥有 OSCP,OSEP,OSWE,OSED&…...

每日一题29——山峰数组的顶部
符合下列属性的数组 arr 称为 山峰数组(山脉数组) : arr.length > 3 存在 i(0 < i < arr.length - 1)使得: arr[0] < arr[1] < ... arr[i-1] < arr[i] arr[i] > arr[i1] > ... &g…...

Linux- 系统随你玩之--好用到炸裂的系统级监控、诊断工具
文章目录1、前言2、lsof介绍2.1、问题来了: 所有用户都可以采用该命令吗?3、 服务器安装lsof3.1、安装3.2、检查安装是否正常。4、lsof 命令4.1、常用功能选项4.2、输出内容4.2.1 、FD和 TYPE列5、 lsof 命令实操常见用法6 、常用组合命令7、 结语1、前言…...

第十三节 继承
什么是继承? java中提供一个关键字extends,用这个关键字,我们可以让一个类和另一个类建立父子关系。 public class Student extends People{} student为子类(派生类),people为父类(基类或者超类…...

【优化】性能优化Springboot 项目配置内置Tomcat使用Http11AprProtocol(AIO)
Springboot 项目配置内置tomcat使用Http11AprProtocol(AIO) Windows版本 1.下载Springboot对应版本tomcat包 下载地址 Apache Tomcat - Apache Tomcat 9 Software Downloads 找到bin目录下 tcnative-1.dll 文件 2 放到jdk的bin目录下 Linux版本 在Springboot中内嵌的Tomcat默…...

SpringBoot之@ConfigurationProperties、@EnableConfigurationProperties
ConfigurationProperties 这个注解不仅可以为yml某个类注入还可以为第三方bean绑定属性 为yml某个类注入 只要将对应的yml类对象声明实体pojo并交给spring容器管理,再在类上使用ConfigurationProperties绑定对应的类名即可 涉及到两个知识点,这个类对…...

数组一次性删除多条数据
需求描述 最后提交时删除表格中的空行 实现方法 单行删除 - 并不是一次性删除 表格每行的最后设置删除按钮,点击时将当前行的索引传递给方法,splice 删除当前行。 <el-table :data"tableData" class"myTable" border>..…...

相机删除照片如何恢复?一键解决它
相机删除照片如何恢复?喜欢用相机拍照的人,总会在空闲时多拍几张,这使我们相机中会储存大量的、各种各样的照片。等到回家后,在进行删除,并选出比较好的照片。但也很容易就误删了一些好看的照片。碰到这种意外事&#…...

vue3搭建教程(基于webpack+create-vue+ element-plus)
前言使用vue脚手架搭建vuetswebpack项目搭建步骤:下载node 版本可以 12 或者14或者 16.0,此次使用的>16.0版本,vue-cli通过npm i -g vue/cli 升级到了 vue cli v5.0.8建目录,如(vue3Study)用IDE工具打开…...

代码随想录算法训练营第四十二天 | leetcode 1049. 最后一块石头的重量 II,494. 目标和,474.一和零
代码随想录算法训练营第四十二天 | leetcode 1049. 最后一块石头的重量 II,494. 目标和,474.一和零1049. 最后一块石头的重量 II494. 目标和474.一和零1049. 最后一块石头的重量 II 题目: 有一堆石头,每块石头的重量都是正整数。…...

Java8中Lambda表达式之Collection 的常见用法
背景 在java8中引入了Lambda表达式。其实,他就是一个匿名函数。我们经常会用到一些循环遍历,起始完全就可以通过Lambda来简化我们不必要的操作,下面我们来看一下Lambda常用的方法。 准备条件 DataBuilderprivate static class Person {priv…...

SpringCloud系列知识快速复习 -- part 2(Sentinel微服务保护,Seata分布式事务,Redis分布式缓存和多级缓存)
SpringCloud系列知识快速复习 -- part 2(Sentinel微服务保护,Seata分布式事务,Redis分布式缓存和多级缓存Sentinel微服务保护什么是雪崩问题?解决方法服务保护技术对比流量控制簇点链路Sentinel流控模式流控效果热点参数限流隔离和…...

设置CentOS7的时间与网络同步
1.设置时区为北京时间 [rootlocalhost ~]# timedatectl set-timezone Asia/Shanghai 2.查看系统时间 [rootlocalhost ~]# timedatectl Local time: 四 2023-03-02 17:40:41 CST #系统时间 Universal time: 四 2023-03-02 09:40:41 UTC …...

java开发手册之编程规约
文章目录编程规约命名风格常量定义代码格式OOP规约集合处理并发处理控制语句注释规约其它编程规约 命名风格 1.代码中的命名均不能以下划线或者美元符号开始,也不能以下划线或者美元符号结束 例如:_name | name__ | name$ | $name2.代码中的命名严…...