当前位置:网站首页>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
边栏推荐
- [combinatorics] recursive equation (example of solving recursive equation without multiple roots | complete process of solving recursive equation without multiple roots)
- Simple configuration of postfix server
- Open vsftpd port under iptables firewall
- Simple use of unity pen XR grab
- How do large consumer enterprises make digital transformation?
- Test your trained model
- vs2013已阻止安装程序,需安装IE10
- 绝对定位时元素水平垂直居中
- One brush 149 force deduction hot question-10 regular expression matching (H)
- 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
猜你喜欢

Unity notes unityxr simple to use
![[UE4] brush Arctic pack high quality Arctic terrain pack](/img/e7/bc86bd8450b0b2bdec8980a2aa1a10.jpg)
[UE4] brush Arctic pack high quality Arctic terrain pack

大变局!全国房价,跌破万元大关

C language modifies files by line

人生还在迷茫?也许这些订阅号里有你需要的答案!

1164 Good in C

IntelliJ 2021.3 short command line when running applications

Take you to API development by hand

互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼

Kotlin learning quick start (7) -- wonderful use of expansion
随机推荐
STM32H7 HAL库SPI DMA发送一直处于busy的解决办法
Svn full backup svnadmin hotcopy
Stm32h7 Hal library SPI DMA transmission has been in busy solution
Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing
C language string practice
Wechat applet for the first time
[combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
C language string inversion
[UE4] brush Arctic pack high quality Arctic terrain pack
Open vsftpd port under iptables firewall
Loop through JSON object list
Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
Apache服务挂起Asynchronous AcceptEx failed.
How to read the source code [debug and observe the source code]
Installation and configuration of network hard disk NFS
List of financial products in 2022
Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
LeetCode13.罗马数字转整数(三种解法)
互聯網醫院HIS管理平臺源碼,在線問診,預約掛號 智慧醫院小程序源碼
Design e-commerce spike
https://www.bilibili.com/video/BV1g4411H78N?spm_id_from=333.337.search-card.all.click&vd_source=0471cde1c644648fafd07b54e303c905