当前位置:网站首页>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
边栏推荐
- 记录关于银行回调post请求405 问题
- jvm-运行时数据区
- SQL Injection (POST/Search)
- 叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
- Stack application (balancer)
- Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)
- 挡不住了,国产芯片再度突进,部分环节已进到4nm
- 核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)
- Qt学习23 布局管理器(二)
- Flutter dynamic | fair 2.5.0 new version features
猜你喜欢
Summary of common error reporting problems and positioning methods of thrift
SQL Injection (GET/Select)
Golang - command line tool Cobra
Uniapp tips - scrolling components
挡不住了,国产芯片再度突进,部分环节已进到4nm
[redis] cache warm-up, cache avalanche and cache breakdown
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心
MySQL 数据处理值增删改
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
Go language unit test 3: go language uses gocovey library to do unit test
随机推荐
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
Mastering the cypress command line options is the basis for truly mastering cypress
Sequence table (implemented in C language)
GoLand 2021.1: rename the go project
JS continues to explore...
[combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
Failure of vector insertion element iterator in STL
3D视觉——2.人体姿态估计(Pose Estimation)入门——OpenPose含安装、编译、使用(单帧、实时视频)
Screenshot of the operation steps of upload labs level 4-level 9
Qt学习17 对话框及其类型
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
SQL Injection (AJAX/JSON/jQuery)
“又土又穷”的草根高校,凭什么被称为“东北小清华”?
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
金属有机骨架MIL-88负载阿霉素DOX|叶酸修饰UiO-66-NH2负载阿霉素[email protected]纳米粒子
Selenium browser (1)
Logback log sorting
怎样删除对象的某个属性或⽅法
Spring cup eight school league
28:第三章:开发通行证服务:11:在配置文件中定义属性,然后在代码中去获取;