首页 > 其他分享 >Qt5.12实战之QMessageBox消息框使用

Qt5.12实战之QMessageBox消息框使用

时间:2023-03-25 12:02:37浏览次数:37  
标签:实战 Qt5.12 自定义 question Critical QMessageBox msg warning


  1. 使用前引用头文件 #include <QMessageBox>
  2. 如要使用中文需要使用 QString::fromLocal8Bit 来转换
  3. QMessageBox支持6种类型的消息框,包含自定义的


Qt5.12实战之QMessageBox消息框使用_开发语言


information:

QMessageBox::information(this,
                             "Information",
                             "this is informations");



Qt5.12实战之QMessageBox消息框使用_开发语言_02


critical:

QMessageBox::critical(this,
                          "Critical",
                          "this is Critical text");



Qt5.12实战之QMessageBox消息框使用_开发语言_03


question:

QMessageBox::question(this,
                          "Question",
                          "this is an question ?",
                          QMessageBox::Ok,
                          QMessageBox::Cancel);



Qt5.12实战之QMessageBox消息框使用_qt_04


warning:

QMessageBox::warning(this,
                         "Warning",
                         "this is an warning content!");



Qt5.12实战之QMessageBox消息框使用_qt_05


about:

QMessageBox::about(this,
                       "About",
                       "this is an ablut text");



Qt5.12实战之QMessageBox消息框使用_自定义_06


自定义:



Qt5.12实战之QMessageBox消息框使用_开发语言_07


QMessageBox msg(QMessageBox::NoIcon,
                    "CustMsg",
                    "this is an custom msg",
                    QMessageBox::Yes|
                    QMessageBox::No|
                    QMessageBox::Cancel);

    msg.setIcon(QMessageBox::Critical);
    msg.setWindowTitle(CH("自定义消息框"));
    msg.setText(CH("这是自定义消息框的内容!"));;
    msg.setDefaultButton(QMessageBox::Yes);//默认按钮
    int m = msg.exec();
    switch(m){
        case QMessageBox::Yes:
            qDebug()<<CH("选择了Yes");
        break;
        case QMessageBox::No:
            qDebug()<<CH("选择了No");
        break;
        case QMessageBox::Cancel:
            qDebug()<<CH("选择了Cancel");
        break;
        default:
            break;
    }

标签:实战,Qt5.12,自定义,question,Critical,QMessageBox,msg,warning
From: https://blog.51cto.com/remotedev/6149144

相关文章