Qt学习笔记 QMessageBox

时间:2022-04-25
本文章向大家介绍Qt学习笔记 QMessageBox,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

Qt的几种MessageBox

1.Infomation类型

QMessageBox::information(this,tr("hello"),tr("title"));

2.Question类型

    QMessageBox::StandardButton returnBtn;
    returnBtn = QMessageBox::question(this,tr("hello have problem?"),tr("error!"),QMessageBox::Yes|QMessageBox::No);
    if(returnBtn==QMessageBox::Yes)
    {
        QMessageBox::information(this,tr("Yes!"),tr("error"));
    }

3.Warning类型

QMessageBox::warning(this,tr("warning!"),tr("warning!"));

4.自定义类型

    QMessageBox msg;
    msg.setText("customer!");
    msg.setWindowTitle(tr("titleHaHa"));
    msg.setStandardButtons(QMessageBox::Ok|QMessageBox::Cancel);
    msg.exec();