当前位置:网站首页>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
边栏推荐
- Qt学习22 布局管理器(一)
- How to promote the progress of project collaboration | community essay solicitation
- 栈应用(平衡符)
- Windos creates Cordova prompt because running scripts is prohibited on this system
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- Uniapp tips - scrolling components
- [combinatorics] permutation and combination (examples of combinatorial number of multiple sets | three counting models | selection problem | combinatorial problem of multiple sets | nonnegative intege
- 叶酸修饰的金属-有机骨架(ZIF-8)载黄芩苷|金属有机骨架复合磁性材料([email protected])|制备路线
- [combinatorics] permutation and combination (two counting principles, examples of set permutation | examples of set permutation and circle permutation)
- Qt学习18 登录对话框实例分析
猜你喜欢

Solve MySQL 1045 access denied for user 'root' @ 'localhost' (using password: yes)

可编程逻辑器件软件测试

核酸修饰的金属有机框架药物载体|PCN-223金属有机骨架包载Ad金刚烷|ZIF-8包裹阿霉素(DOX)

解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

JVM family - overview, program counter day1-1

jvm-对象生命周期

Halcon combined with C # to detect surface defects -- Halcon routine autobahn
![Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:](/img/2f/33504391a661ecb63d42d75acf3a37.png)
Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:

如何使用lxml判断网站公告是否更新

双向链表(我们只需要关注插入和删除函数)
随机推荐
How to use lxml to judge whether the website announcement is updated
Heap structure and heap sort heapify
软件测试工作那么难找,只有外包offer,我该去么?
Qt学习24 布局管理器(三)
Unity render streaming communicates with unity through JS
Use docker to build sqli lab environment and upload labs environment, and the operation steps are provided with screenshots.
太阳底下无新事,元宇宙能否更上层楼?
Dynamic programming 01 knapsack and complete knapsack
Dlopen() implements dynamic loading of third-party libraries
Leetcode-1175. Prime Arrangements
记录关于银行回调post请求405 问题
pytorch 载入历史模型时更换gpu卡号,map_location设置
RocksDB LRUCache
Using registered classes to realize specific type matching function template
Spring cup eight school league
小项目(servelt+jsp+mysql+EL+JSTL)完成一个登录功能的Servlet,具有增删改查的操作。实现登录身份验证,防止非法登录,防止多点登录,记住用户名密码功能。
静态链表(数组的下标代替指针)
There is nothing new under the sun. Can the meta universe go higher?
Static linked list (subscript of array instead of pointer)
Qt学习25 布局管理器(四)