zoukankan      html  css  js  c++  java
  • Qt 中的消息对话框

    1. QMessagebox 类的几个静态成员函数,可以直接调用创建对话框

    StandardButton critical(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
    StandardButton information(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)
    StandardButton question(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = StandardButtons( Yes | No ), StandardButton defaultButton = NoButton)
    StandardButton warning(QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton)

    2.static StandardButton QMessageBox::information ( QWidget * parent, const QString & title, const QString & text, StandardButtons buttons = Ok, StandardButton defaultButton = NoButton );

      然后看它那一堆参数,第一个参数parent,说明它的父组件;第二个参数title,也就是对话框的标题;第三个参数text,是对话框显示的内容;第四个参数buttons,声明对话框放置的按钮,默认是只放置一个OK按钮,这个参数可以使用或运算,例如我们希望有一个Yes和一个No的按钮,可以使用QMessageBox::Yes | QMessageBox::No,所有的按钮类型可以在QMessageBox声明的StandarButton枚举中找到;第五个参数defaultButton就是默认选中的按钮,默认值是NoButton,也就是哪个按钮都不选中。

       注意,static函数都是要返回一个StandardButton,我们就可以通过判断这个返回值来对用户的操作做出相应。

    int ret = QMessageBox::warning(this, tr("My Application"),
                                   tr("The document has been modified.
    "
                                      "Do you want to save your changes?"),
                                   QMessageBox::Save | QMessageBox::Discard
                                   | QMessageBox::Cancel,
                                   QMessageBox::Save);
     
    switch (ret) {
      case QMessageBox::Save:
          // Save was clicked
          break;
      case QMessageBox::Discard:
          // Don't Save was clicked
          break;
      case QMessageBox::Cancel:
          // Cancel was clicked
          break;
      default:
          // should never be reached
          break;
    }

    endl;

  • 相关阅读:
    性能测试十三:linux常用命令
    性能测试十二:jmeter进阶之java请求参数化
    性能测试十一:jmeter进阶之java请求
    性能测试十:jmeter进阶之webService与socket
    性能测试九:jmeter进阶之beanshell的使用+断言
    初识贝叶斯网络
    初识贝叶斯网络
    再学贝叶斯网络--TAN树型朴素贝叶斯算法
    再学贝叶斯网络--TAN树型朴素贝叶斯算法
    再学贝叶斯网络--TAN树型朴素贝叶斯算法
  • 原文地址:https://www.cnblogs.com/icmzn/p/7459023.html
Copyright © 2011-2022 走看看