案例一:
点击(此处)折叠或打开
- QMessageBox msgBox;
- msgBox.setText("The document has been modified.");
- msgBox.setInformativeText("Do you want to save your changes?");
- msgBox.setStandardButtons(QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel);
- msgBox.setDefaultButton(QMessageBox::Save);
- int ret = msgBox.exec();
- 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;
- }
案例二:
点击(此处)折叠或打开
- int ret = QMessageBox::warning(this,
- tr("My Application"),
- tr("The document has been modified.\n"
- "Do you want to save your changes?"),
- QMessageBox::Save | QMessageBox::Discard | QMessageBox::Cancel,
- QMessageBox::Save);
案例三:添加按钮、判断哪个按钮按下
点击(此处)折叠或打开
- QMessageBox msgBox;
- QPushButton *connectButton = msgBox.addButton(tr("Connect"), QMessageBox::ActionRole);
- QPushButton *abortButton = msgBox.addButton(QMessageBox::Abort);
- if(msgBox.clickedButton() == connectButton)
- {
- // connect
- }
- else if(msgBox.clickedButton() == abortButton)
- {
- // abort
- }
- msgBox.exec();
给主人留下些什么吧!~~
评论热议