Qt - QMessageBox

按钮角色枚举值

 

图标枚举值

 

标准按钮枚举

构造函数:

QMessageBox ( QWidget * parent = 0 )
2 QMessageBox ( Icon icon, const QString & title, const QString & text, StandardButtons buttons = NoButton, QWidget * parent = 0, Qt::WindowFlags f = Qt::Dialog | Qt::MSWindowsFixedSizeDialogHint )

4个静态函数:

void    about ( QWidget * parent, const QString & title, const QString & text )
void    aboutQt ( QWidget * parent, const QString & title = QString() )
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 = Ok, StandardButton defaultButton = NoButton )
StandardButton    warning ( 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);

 

QMessageBox::about(NULL, "About", "About this <font color='red'>application</font>");

QMessageBox msgBox;msgBox.setWindowTitle("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;
}

 本文福利,费领取Qt开发学习资料包、技术视频,内容包括(C++语言基础,C++设计模式,Qt编程入门,QT信号与槽机制,QT界面开发-图像绘制,QT网络,QT数据库编程,QT项目实战,QSS,OpenCV,Quick模块,面试题等等)↓↓↓↓↓↓见下面↓↓文章底部点击费领取↓↓

猜你喜欢

转载自blog.csdn.net/m0_73443478/article/details/130031239