模态对话框创建:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDialog>
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);connect(ui->actionNew,&QAction::triggered,[=](){QDialog dlg;dlg.resize(200,100);dlg.exec();qDebug()<<"模态对话框弹出了";});
}MainWindow::~MainWindow()
{delete ui;
}
非模态对话框创建:
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include<QDialog>
#include <QDebug>MainWindow::MainWindow(QWidget *parent) :QMainWindow(parent),ui(new Ui::MainWindow)
{ui->setupUi(this);connect(ui->actionNew,&QAction::triggered,[=](){QDialog *dlg2 = new QDialog (this);dlg2->resize(200,100);dlg2->show();dlg2->setAttribute(Qt::WA_DeleteOnClose);//55号 属性qDebug()<<"非模态对话框弹出了";});
}MainWindow::~MainWindow()
{delete ui;
}