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

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. EF提供的3中查询方式

    1. Linq to Entities using (TestEntities te = new TestEntities()) { var user = from a in te.User wher ...

  2. Amazon Virtual Private Cloud(虚拟专有网络)官方文档通读

    一.什么是Amazon VPC? 参考资料: 官网文档 https://docs.aws.amazon.com/zh_cn/AmazonVPC/latest/UserGuide/VPC_Introdu ...

  3. Delphi StringReplace – 替换字符函数

    Delphi StringReplace – 替换字符函数 Delphi中的StringReplace函数是SysUtils单元中自带的函数,该函数可以替换字符串中的指定字符. 1 2 3 4 5 6 ...

  4. JZOJ.5274【NOIP2017模拟8.14】数组

    Description

  5. ios 统一设计,iOS6也玩扁平化

    转:http://esoftmobile.com/2014/01/14/build-ios6-ios7-apps/ 前言 前段时间,苹果在它的开发者网站上放出了iOS系统安装比例,其中iOS7占到78 ...

  6. java读取项目资源文件的方法

    1.把资源文件放在项目的Resource文件夹下,并使其设置成为资源文件夹(通过idea或者eclise)2. Thread.currentThread().getContextClassLoader ...

  7. Powershell ——findstr

    从文件中找出关键字 $colItems = Get-ChildItem d:\test #定义文件夹的路径 foreach ($i in $colItems) #循环获取文件夹下的txt文件 { $f ...

  8. 修改SQL Server 数据库的编码

    ALTER DATABASE [dbnam] collate SQL_Latin1_General_CP1_CI_AS 查询编码号:SELECT COLLATIONPROPERTY('SQL_Lati ...

  9. [科普]什么是SysWow64

    Wow!什么是Wow64 今天有个同事,被SysWow64搞晕了.这里简单介绍一下. 64位的Windows并不是简单地把所有东西都编译成64位就万事大吉的.关于64位的CPU应该做成什么样子,Int ...

  10. access variables from the global scope 在全局范围内访问变量的2种方法

    w http://php.net/manual/zh/language.variables.scope.php http://php.net/manual/en/language.variables. ...