• QMesageBox的使用


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

    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");

  • 相关阅读:
    如何在windows下搭建PHP运行环境?
    如何安装Moodle课程包
    2009人工智能与教育应用国际学术会议 (ICAIE'09)
    利用EasyPHP搭建Moodle平台(转)
    SharePoint Server 2007序列号 (转 )
    2009 International Conference on ELearning, EBusiness, Enterprise Information Systems, and EGovernment (EEEE 2009)
    第二届IEEE信息技术与教育国际会议
    原创:利用APMserv快速搭建Moodle平台
    PHP数组的定义、初始化和数组元素的显示
    office2007新建 Microsoft Office Word 文档.docx,打开后弹出转换文件对话框的解决办法
  • 原文地址:https://www.cnblogs.com/judes/p/6668436.html
Copyright © 2020-2023  润新知