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

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的使用的更多相关文章

  1. 在Qt Creator 和在 vs2012 里添加信号和槽

    原文地址:http://www.cnblogs.com/li-peng/p/3644812.html 作者:李鹏 出处:http://www.cnblogs.com/li-peng/ 本文版权归作者和 ...

  2. QT笔记之VS开发程序遇到的问题

    转载:http://www.cnblogs.com/li-peng/p/3644812.html 转载:http://www.cnblogs.com/csuftzzk/p/VS_Qt_Experien ...

  3. Python: PySide(PyQt)QMessageBox按钮显示中文

    习惯了Delphi.c#调用系统MessageBox本地化显示,待用PySide调用时,Qt原生提示对话框,默认以英文显示. 如何本地化呢? 参考些资料,加以摸索,实现所需效果.并可根据此思路,设计自 ...

随机推荐

  1. ExtJs4学习(六)MVC中的Model

    Model定义的两种方式 第一种 Ext.define("User",{ extend:"Ext.data.Model", fields:[{ name:'us ...

  2. springside4

    https://github.com/springside/springside4/wiki/Design Design 1. Web MVC Framwork: SpringMVC3.0 Restf ...

  3. cocos3.9 windows平台 AssetsManager创建文件失败问题

    在做热更新功能时用到了AssetsManager,发现在windows平台总是报CREATE_FILE错误,errorStr "Can't renamefile from: xxx.tmp ...

  4. git和svn的详细对比

    近期就[版本管理工具是否进行切换SVN->Git]的问题进行了讨论,于是对svn和Git进行了相关研究,进而梳理出Git的特点(优.缺点),最后将Git与SVN进行了对比,对比结果详见下方内容. ...

  5. 移动APP自动化测试框架

    简介 移动APP的UI自动化测试长久以来一直是一个难点,难点在于UI的”变”, 变化导致自动化用例的大量维护.从分层测试的角度,自动化测试应该逐层进行.最大量实现自动化测试的应该是单元测试,最容易实现 ...

  6. Kubernetes资源创建yml语法

    前言 在是用kubernetes中,我们对资源的创建大部分都是通过 1 kubelet create -f RESOURCE.yaml 刚开看的时候不免有一些迷茫,看不懂语法,不知道怎么写:今天本文就 ...

  7. Exchange Version and UpdateRollups

    Exchange Server 2010 Product name Build number Date KB Microsoft Exchange Server 2010 RTM 14.0.639.2 ...

  8. 【Python之路】第十八篇--MySQL(一)

    一.概述 1.什么是数据库 ? 答:数据的仓库. 2.什么是 MySQL.Oracle.SQLite.Access.MS SQL Server等 ? 答:他们均是一个软件,都有两个主要的功能: a. ...

  9. qmake make install

    一般的qmake生成的Makefile是没有 make install的 方法: 在.pro中做文章 比如你要安装libEbookDataBase.so*到目录 /usr/local/lib .pro ...

  10. java中的System.copyof()与Array.copyof()区别

    java中的System.copyof()与Array.copyof()区别 在复制数组时我们可以使用System.copyof(),也可以使用Array.copyof(),但是它们之间是有区别的.以 ...