Qt 模态对话框和消息对话框

Qt 模态对话框和消息对话框_第1张图片

分类:
1、模态对话框:不可以对其他窗口进行操作 阻塞
        QDialog dlg(this);
        dlg.exec();
2、非模态对话框:可以对其他窗口进行操作 防止一闪而过,创建到了堆区
        QDialog* dlg = new Dialog(this);
        dlg.show();
        dlg->setAttribute(Qt::WA_DeleteOnClose);//55号 属性

#include "mainwindow.h"
#include "ui_mainwindow.h"
#include
#include
#include
#include
#include
#include
#include
/*
    分类:
        模态对话框:不可以对其他窗口进行操作 阻塞
            QDialog dlg(this);
            dlg.exec();
        非模态对话框:可以对其他窗口进行操作
            防止一闪而过,创建到了堆区
            QDialog* dlg = new Dialog(this);
            dlg.show();
            dlg->setAttribute(Qt::WA_DeleteOnClose);//55号 属性
*/

MainWindow::MainWindow(QWidget *parent)
	: QMainWindow(parent)
{
	ui.setupUi(this);
    connect(ui.actionNew, &QAction::triggered, [=]() {
        //对话框 分类
        //模态对话框(不可以对其他窗口进行操作) 非模态对话框(可以对其他窗口进行操作)
        //模态创建 阻塞
        /*
        QDialog dlg(this);

        dlg.resize(200,100);
        dlg.exec();
        qDebug()<<"模态对话框弹出了";*/

        //非模态对话框
        QDialog* dlg2 = new QDialog(this);
        dlg2->resize(200, 100);
        dlg2->show();
        dlg2->setAttribute(Qt::WA_DeleteOnClose);//55号 属性
        qDebug() << "非模态对话框弹出了";

        
     });
}

 

你可能感兴趣的:(qt,ui,开发语言)