Chinaunix首页 | 论坛 | 博客
  • 博客访问: 370223
  • 博文数量: 50
  • 博客积分: 0
  • 博客等级: 民兵
  • 技术积分: 641
  • 用 户 组: 普通用户
  • 注册时间: 2014-05-09 22:35
个人简介

不怕你失败,就怕你爬不起来。

文章分类

全部博文(50)

文章存档

2014年(50)

我的朋友

分类: C/C++

2014-08-20 23:59:32

案例一:

点击(此处)折叠或打开

  1. QMessageBox msgBox;
  2. msgBox.setText("The document has been modified.");
  3. msgBox.setInformativeText("Do you want to save your changes?");
  4. msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
  5. msgBox.setDefaultButton(QMessageBox::Save);
  6. int ret = msgBox.exec();
  7. switch (ret)
  8. {
  9.  case QMessageBox::Save:
  10.  // Save was clicked
  11.  break;
  12.  case QMessageBox::Discard:
  13.  // Don't Save was clicked
  14.  break;
  15.  case QMessageBox::Cancel:
  16.  // Cancel was clicked
  17.  break;
  18.  default:
  19.  // should never be reached
  20.  break;
  21.  }



      案例二:

点击(此处)折叠或打开

  1. int ret = QMessageBox::warning(this,
  2.                                tr("My Application"),
  3.                                tr("The document has been modified.\n"
  4.                                   "Do you want to save your changes?"),
  5.                                QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
  6.                                QMessageBox::Save);


案例三:添加按钮、判断哪个按钮按下

点击(此处)折叠或打开

  1. QMessageBox msgBox;
  2. QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
  3. QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
  4. if(msgBox.clickedButton() == connectButton)
  5. {
  6.      // connect
  7. }
  8. else if(msgBox.clickedButton() == abortButton)
  9. {
  10.      // abort
  11. }
  12. msgBox.exec();


阅读(1818) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~