QMesageBox的使用

摘要:
1、 使用构造函数弹出对话框1.QMessageBoxmsgBox//最简单的对话框不包含QStringstr=“test”;消息框。setText(str);消息框。exec();2、 QMessageBox消息(QMessageBox::NoIcon,“Title”,“Contentwithincon.”);//添加了图片的对话框消息

一、使用构造函数弹出对话框

1、 QMessageBox msgBox;//最简单的对话框,里面什么也没有

  QString str = “test”;

  msgBox.setText(str);

  msgBox.exec();

2、

  QMessageBox message(QMessageBox::NoIcon, "Title", "Content with icon."); //加入了图片的对话框
  message.setIconPixmap(QPixmap("icon.png"));
  message.exec();

二、使用QMessageBox的静态方法

  1、消息对话框,函数原型:StandardButton QMessageBox::information(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok, StandardButton   defaultButton = NoButton)
  QMessageBox::information(NULL, "Title", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);//
  2、错误对话框,函数原型:StandardButton QMessageBox::critical(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok,  StandardButton defaultButton = NoButton)
  QMessageBox::critical(NULL, "critical", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
  3、警告对话框,函数原型:StandardButton QMessageBox::warning(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
  QMessageBox::warning(NULL, "warning", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
  4、问题对话框,函数原型:StandardButton QMessageBox::question(QWidget *parent, const QString &title, const QString &text, StandardButtons buttons = StandardButtons( Yes | No ), StandardButton defaultButton = NoButton)
  QMessageBox::question(NULL, "question", "Content", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
  5、关于对话框,函数原型:void QMessageBox::about(QWidget *parent, const QString &title, const QString &text)

    QMessageBox::about(NULL, "About", "About this application");

三、如何对二中的返回值做判断

  1~4函数都是返回StandardButton,所以:

QMessageBox::StandardButton rb = QMessageBox::question(NULL, "Show Qt", "Do you want to show Qt dialog?", QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes);
if(rb == QMessageBox::Yes)
  QMessageBox::aboutQt(NULL, "About Qt");

免责声明:文章转载自《QMesageBox的使用》仅用于学习参考。如对内容有疑问,请及时联系本站处理。

上篇[ PyQt入门教程 ] Qt Designer工具的使用7-FreeRTOS时间片进行任务调度下篇

宿迁高防,2C2G15M,22元/月;香港BGP,2C5G5M,25元/月 雨云优惠码:MjYwNzM=

相关文章

Android指针管理:RefBase,SP,WP (二)

(1)在Android中,RefBase结合了sp和wp,实现了一套通过引用计数的方法来控制对象声明周期的方法。 RefBase的定义在/frameworks/base/include/utils/RefBase.h,实现在/frameworks/base/libs/utils/RefBase.cpp。wp的定义在/frameworks/base/incl...

ES6-10笔记(let&const -- Array)

大纲 scope-作用域 作用域是指程序源代码中定义变量的区域,规定了如何查找变量,也就是确定当前执行代码对变量的访问权限。 JavaScript作用域共有两种主要的工作模型——词法作用域(静态作用域)和动态作用域。 JavaScript默认采用词法作用域(lexical scoping),也就是静态作用域。 词法作用域是由开发者在写代码时将变量和...

说说接口封装

今天给同事封装了一个接口,说起接口封装的事情,其实其实很有的聊。很多时候,说一个服务好,一个服务烂,实际上都是在吐槽服务队外暴露的接口好坏。不管什么语言,封装接口,抽象起来,就是由一个函数名,若干个参数,若干个返回值组成的。封装的好坏,就在这几个上面。 函数名 首先是函数名。函数名的好坏很明显,我的观点,是否简单,不重复。比如在一个User类中你封装一个...

QList内存释放(看它内部存储的是否是Object,另外还有qDeleteAll)

QList<T> 的释放分两种情况: 1.T的类型为非指针,这时候直接调用clear()方法就可以释放了,看如下测试代码 #include <QtCore/QCoreApplication>#include <QList>#include <QString> int main(int argc, char *...

OpenGL ES着色器语言----------------储存修饰符

一、存储修饰符 本地变量只能使用存储修饰符const。 函数参数只能用const。函数返回值类型和结构体字段不要使用const。 从一个运行时着色器到下一个运行时着色器之间进行数据类型通信是不存在的。这阻止了同一个着色器在多个顶点和片元之间同时执行。 没有存储修饰符或仅仅使用const修饰符的全局变量,可能在main()执行前进行初始化。Uniforms...

从零开始的野路子React/Node(9)Antd + multer实现文件上传

最近心血来潮,打算自己捣腾个web app来练练手(虽然大概率会半路弃坑……),其中有一部分是关于文件上传的,在实现的过程中遇到了一些坑,于是打算把血泪教训都记录下来。 前端的部分采用了Antd,不得不说真是香,至少比我司内部的前端库香了1000倍……事半功倍。后端部分则主要通过multer来实现,目测应该是一种比较通用的做法? 1、捯饬前端 首先我们新建...