当前位置:网站首页>QT learning diary 9 - dialog box
QT learning diary 9 - dialog box
2022-07-03 17:23:00 【herb. dr】
Learn video links
Catalog
Two 、 The system provides a good dialog
One 、 Custom dialog
1.1 Modal dialog :
You cannot operate on other windows
1.2 modeless dialog box :
You can operate other windows
1.3 Case study
The following figure shows the modeless dialog

After opening the window in the interface , You can modify the original interface
Modal dialog
When running pop-up , The function is blocked in dlg.exec(); This line of code here , Click on X after , Output QDebug

establish modeless dialog box

Function is not blocked in dlg2->show(); Here is the sentence , Because it prevents a flash , So create to heap
At the same time, we should pay attention to , After this function applies for memory , No memory Freed , Memory leaks may occur later
We need to be in X Free the memory when you drop the window , Add the middle line of code

Two 、 The system provides a good dialog
2.1 Standard dialog box
The so-called standard dialog box , yes Qt A set of built-in dialog boxes , Used to simplify development . in fact , There are a lot of dialog boxes that are generic , Like opening a file 、 Set the color 、 Print settings, etc . These dialog boxes are almost the same in all programs , Therefore, there is no need to implement such a dialog box in every program
Qt The built-in dialog boxes of are roughly divided into the following categories :
QColorDialog: Choose a color
FileDialog: Choose a file or directory
FontDialog: Select the font
QInputDialog: Allow the user to enter a value , And return its value to
QMessageBox: Modal dialog , Used to display information 、 Asking questions, etc
QPageSetupDialog: Provide paper related options for the printer
QPrintDialog: Printer configuration
QPrintPreviewDialog: Print preview
ProgressDialog: Display operation process
2.2 Message dialog

2.3 Color dialog

Click on OK in the future , Function to get the return value , And jump into the main window

Be careful :
1、2.2 and 2.3 The function of can be written in connect Inside
#include "mainwindow.h"
#include "ui_mainwindow.h"
#include <QDialog>
#include <QDebug>
#include <QMessageBox>
#include <QColorDialog>
MainWindow::MainWindow(QWidget *parent)
: QMainWindow(parent)
, ui(new Ui::MainWindow)
{
ui->setupUi(this);
connect(ui->actionnew, &QAction::trigger, [](){
// Warning dialog
// QMessageBox::warning(this, "warning", " Warning ");
// Other standard dialog boxes
// Color dialog
QColor color = QColorDialog::getColor(QColor(255, 0, 0));
qDebug() << "r = " << color.red() << " g = " << color.green() << " b = " << color.blue();
});
}
MainWindow::~MainWindow()
{
delete ui;
}2、 Color dialog QColor(255, 0, 0, 255) There is a fourth parameter , The default is 255 That is, four parameters
2.4 File dialog
Pass in the parameter :
this: father
...: title
...: Default open path
...: Format to open ( Filter other formats )
Return value :
Qstring、 Selected file path
边栏推荐
- C language string practice
- Talk about several methods of interface optimization
- Where is the database account used when running SQL tasks in data warehouse tasks configured
- Unity notes unityxr simple to use
- 企业级自定义表单引擎解决方案(十一)--表单规则引擎1
- VM11289 WAService. js:2 Do not have __ e handler in component:
- Apache服务挂起Asynchronous AcceptEx failed.
- Golang unit test, mock test and benchmark test
- Kotlin learning quick start (7) -- wonderful use of expansion
- Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
猜你喜欢

大变局!全国房价,跌破万元大关
![[RT thread] NXP rt10xx device driver framework -- pin construction and use](/img/75/b4f034bfe49409f76e7fd92758804e.png)
[RT thread] NXP rt10xx device driver framework -- pin construction and use
![How to read the source code [debug and observe the source code]](/img/40/a2fca67bcde3c468a739c6990325f4.jpg)
How to read the source code [debug and observe the source code]

Unity notes unityxr simple to use

1164 Good in C

Hongmeng fourth training

新库上线 | CnOpenData中国保险机构网点全集数据

大消费企业怎样做数字化转型?

Take you to API development by hand

Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
随机推荐
September, 19, "cam principle and application" online assignment [Full Score answer]
互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
An example of HP array card troubleshooting
Squid service startup script
Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
vs2013已阻止安装程序,需安装IE10
Type conversion, variable
Kotlin learning quick start (7) -- wonderful use of expansion
【JokerのZYNQ7020】DDS_ Compiler。
2021 ICPC regional competition (Shanghai) g.edge groups (tree DP)
Golang unit test, mock test and benchmark test
PS screen printing brush 131, many illustrators have followed suit
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
New library online | cnopendata complete data of Chinese insurance institution outlets
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
Design e-commerce spike
Test your trained model
kubernetes资源对象介绍及常用命令(三)
Prepare for the golden three silver four, 100+ software test interview questions (function / interface / Automation) interview questions. win victory the moment one raises one 's standard
Installation and configuration of network hard disk NFS
https://www.bilibili.com/video/BV1g4411H78N?spm_id_from=333.337.search-card.all.click&vd_source=0471cde1c644648fafd07b54e303c905