当前位置:网站首页>QT learning 17 dialog box and its types
QT learning 17 dialog box and its types
2022-07-03 13:58:00 【A little black sauce】
Qt Study 17 Dialog box and its type
Concept of dialog box
- Dialog box Is to communicate with users Brief interaction The top window of
- QDialog yes Qt The base class of all multi frame windows in
- QDialog Inherited from QWidget It's a kind of Container type The components of

- QDialog The meaning of
- QDialog As a kind of Dedicated interactive window And exist
- QDialog You can't Embedded in other containers as a subassembly
- QDialog The window style is customized special QWidget
experiment 1 - QWidget and QDialog The difference between
#include "Dialog.h"
#include <QApplication>
#include <QWidget>
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QWidget widget;
QDialog dialog(&widget); // although dialog Set the parent component , however dialog It will still be the top window
dialog.show();
dialog.setWindowTitle("I'am dialog");
widget.show();
widget.setWindowTitle("I'am widget");
return a.exec();
}
#include <QApplication>
#include <QWidget>
#include <QDialog>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
QDialog dialog;
QWidget widget(&dialog); // widget Set the parent component ,widget Will be embedded dialog in
dialog.show();
dialog.setWindowTitle("I'am dialog");
widget.show();
widget.setWindowTitle("I'am widget");
return a.exec();
}
Type of dialog
Modal dialog ( QDialog::exec() )
- After the show Cannot interact with parent window
- It's a kind of Blocking type Dialog call method
modeless dialog box ( QDialog::show() )
- After the show Independent existence Sure At the same time, interact with the parent window
- It's a kind of Non-blocking type Dialog call method
General situation
- The modal dialog box is used for It must depend on the occasion chosen by the user (80%)
- Message tip , File selection , Print settings , etc.
Modeless dialog boxes are used for Occasions with special function settings (20%)
- Search operation , Property settings , etc.
Tips
- stay Stack To create a Modal dialog Is the simplest and most commonly used way
- In general modeless dialog box Need to be in Pile up To create a
- adopt QDialog::setModel Function can create Mixing characteristics The dialog
- modeless dialog box You need to specify the Qt::WA_DeleteOnClose attribute
experiment 2 - Dialog boxes with different features
#ifndef DIALOG_H
#define DIALOG_H
#include <QDialog>
#include <QPushButton>
class Dialog : public QDialog
{
Q_OBJECT
protected:
QPushButton ModalBtn;
QPushButton NormalBtn;
QPushButton MixedBtn;
protected slots:
void ModalBtn_clicked();
void NormalBtn_clicked();
void MixedBtn_clicked();
public:
Dialog(QWidget *parent = 0);
~Dialog();
};
#endif // DIALOG_H
#include "Dialog.h"
#include <QDebug>
// Modal dialog
void Dialog::ModalBtn_clicked()
{
qDebug() << "ModalBtn_clicked() begin";
QDialog dialog(this);
dialog.exec();
qDebug() << "ModalBtn_clicked() end";
}
// modeless dialog box
void Dialog::NormalBtn_clicked()
{
qDebug() << "NormalBtn_clicked() begin";
QDialog *dialog = new QDialog(this); // Modeless dialogs do not block programs , It must be put on the pile
dialog->setAttribute(Qt::WA_DeleteOnClose); // To prevent memory leaks , This line must be added
dialog->show();
qDebug() << "NormalBtn_clicked() end";
}
// Mixed properties dialog box
void Dialog::MixedBtn_clicked()
{
qDebug() << "MixedBtn_clicked() begin";
QDialog *dialog = new QDialog(this);
dialog->setAttribute(Qt::WA_DeleteOnClose);
dialog->setModal(this); // The mixed attribute dialog is based on the modeless dialog
dialog->show();
qDebug() << "MixedBtn_clicked() end";
}
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ModalBtn(this), NormalBtn(this), MixedBtn(this)
{
ModalBtn.setText("Modal Dialog");
ModalBtn.move(20, 20);
ModalBtn.resize(100, 30);
NormalBtn.setText("Normal Dialog");
NormalBtn.move(20, 70);
NormalBtn.resize(100, 30);
MixedBtn.setText("Mixed Dialog");
MixedBtn.move(20, 120);
MixedBtn.resize(100, 30);
connect(&ModalBtn, SIGNAL(clicked()), this, SLOT(ModalBtn_clicked()));
connect(&NormalBtn, SIGNAL(clicked()), this, SLOT(NormalBtn_clicked()));
connect(&MixedBtn, SIGNAL(clicked()), this, SLOT(MixedBtn_clicked()));
resize(140, 170);
}
Dialog::~Dialog()
{
qDebug() << "~Dialog()";
}
#include "Dialog.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog dlg;
dlg.show();
return a.exec();
}
The return value of the dialog
- Only Modal dialog Only then Return value The concept of
- Modal dialog Return value be used for Represent interaction results
- QDialog::exec() The return value of is the interaction result
- void QDialog::done(int i) Close the dialog box and Take parameters as interaction results
- QDialog::Accepted - User operation succeeded
- QDialog::Rejected - User operation failed
experiment 3 - The return value of the dialog
#include "Dialog.h"
#include <QDebug>
void Dialog::ModalBtn_clicked()
{
qDebug() << "ModalBtn_clicked() begin";
done(Accepted);
qDebug() << "ModalBtn_clicked() end";
}
void Dialog::NormalBtn_clicked()
{
qDebug() << "NormalBtn_clicked() begin";
done(Rejected);
qDebug() << "NormalBtn_clicked() end";
}
void Dialog::MixedBtn_clicked()
{
qDebug() << "MixedBtn_clicked() begin";
done(100);
qDebug() << "MixedBtn_clicked() end";
}
Dialog::Dialog(QWidget *parent)
: QDialog(parent), ModalBtn(this), NormalBtn(this), MixedBtn(this)
{
ModalBtn.setText("Modal Dialog");
ModalBtn.move(20, 20);
ModalBtn.resize(100, 30);
NormalBtn.setText("Normal Dialog");
NormalBtn.move(20, 70);
NormalBtn.resize(100, 30);
MixedBtn.setText("Mixed Dialog");
MixedBtn.move(20, 120);
MixedBtn.resize(100, 30);
connect(&ModalBtn, SIGNAL(clicked()), this, SLOT(ModalBtn_clicked()));
connect(&NormalBtn, SIGNAL(clicked()), this, SLOT(NormalBtn_clicked()));
connect(&MixedBtn, SIGNAL(clicked()), this, SLOT(MixedBtn_clicked()));
resize(140, 170);
}
Dialog::~Dialog()
{
qDebug() << "~Dialog()";
}
#include "Dialog.h"
#include <QApplication>
#include <QDebug>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Dialog dlg;
int r = dlg.exec();
if (r == QDialog::Accepted) {
qDebug() << "QDialog::Accepted";
}
else if (r == QDialog::Rejected) {
qDebug() << "QDialog::Rejected";
}
else {
qDebug() << r;
}
return r;
}
Header file usage experiment 2 Header file in .
Summary
- The dialog box is divided into Modal dialog and modeless dialog box
- Modal dialogs are blocked
- Modal dialog boxes are used for user interaction results
- Modeless dialogs are non blocking
- Modeless dialog boxes are used for Occasion of function setting
边栏推荐
- Windos creates Cordova prompt because running scripts is prohibited on this system
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
- Using registered classes to realize specific type matching function template
- Qt学习17 对话框及其类型
- Golang - command line tool Cobra
- Logback log sorting
- Field problems in MySQL
- Qt学习20 Qt 中的标准对话框(中)
- [ACNOI2022]猜数
- [acnoi2022] guess numbers
猜你喜欢

Qt学习17 对话框及其类型

Go: send the get request and parse the return JSON (go1.16.4)

从零开始的基于百度大脑EasyData的多人协同数据标注

可编程逻辑器件软件测试

28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;

NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon

Golang — 命令行工具cobra

Go language web development series 26: Gin framework: demonstrates the execution sequence of code when there are multiple middleware

Comprehensively develop the main channel of digital economy and digital group, and actively promote the utonmos digital Tibet market

SQL Injection (GET/Search)
随机推荐
Qt学习24 布局管理器(三)
Mastering the cypress command line options is the basis for truly mastering cypress
Rasp implementation of PHP
Go 1.16.4: manage third-party libraries with Mod
Golang — template
太阳底下无新事,元宇宙能否更上层楼?
树的深入和广度优先遍历(不考虑二叉树)
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
NFT新的契机,多媒体NFT聚合平台OKALEIDO即将上线
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
windos 创建cordova 提示 因为在此系统上禁止运行脚本
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Qt学习21 Qt 中的标准对话框(下)
SQL Injection (AJAX/JSON/jQuery)
C language standard IO function sorting
GoLand 2021.1.1: configure the multi line display of the tab of the open file
mysql中的字段问题
Depth and breadth first traversal of tree (regardless of binary tree)
[how to earn a million passive income]
叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线