一.简介
QDialog类是所有对话框窗口类,对话框窗口是一个经常用来完成短小任务或者和用户进行简单交互的顶层窗口
对话框分为模态对话框和非模态对话框
模态对话框在关闭它之前,不能与同一个应用程序的其他窗口进行交互
非模态对话框既可以和它交互,也可以和同一个应用程序的其他窗口交互
模态对话框用 exec() 函数显示,或者在 show() 函数之前加上 setModal(true)
非模态对话框用 show() 函数显示
二.窗体框架
// dialog.h #ifndef DIALOG_H #define DIALOG_H #include <QDialog> namespace Ui { class Dialog; } class Dialog : public QDialog { Q_OBJECT public: explicit Dialog(QWidget *parent = nullptr); ~Dialog(); private: Ui::Dialog *ui; }; #endif // DIALOG_H
// dialog.cpp #include "dialog.h" #include "ui_dialog.h" Dialog::Dialog(QWidget *parent) : QDialog(parent), ui(new Ui::Dialog) { ui->setupUi(this); } Dialog::~Dialog() { delete ui; }
// main.cpp #include "dialog.h" #include <QApplication> int main(int argc, char *argv[]) { QApplication a(argc, argv); Dialog w; // w.setModal(true); // w.exec(); w.show(); return a.exec(); }