QMessageBox 用法
Posted 朝闻道
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了QMessageBox 用法相关的知识,希望对你有一定的参考价值。
案例一:
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();
http://blog.csdn.net/jan5_reyn/article/details/38955705
以上是关于QMessageBox 用法的主要内容,如果未能解决你的问题,请参考以下文章