当前位置:网站首页>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
边栏推荐
- Swm32 series Tutorial 4 port mapping and serial port application
- visual studio “通常每个套接字地址(协议/网络地址/端口)只允许使用一次“
- Kubernetes resource object introduction and common commands (III)
- What is your income level in the country?
- VM11289 WAService. js:2 Do not have __ e handler in component:
- C language string inversion
- [try to hack] active detection and concealment technology
- Kotlin learning quick start (7) -- wonderful use of expansion
- Luogu: p1155 [noip2008 improvement group] double stack sorting (bipartite graph, simulation)
- [combinatorics] recursive equation (the problem of solving recursive equation with multiple roots | the problem is raised)
猜你喜欢
Select 3 fcpx plug-ins. Come and see if you like them
1164 Good in C
新库上线 | CnOpenData中国保险机构网点全集数据
QT adjust win screen brightness and sound size
Swm32 series Tutorial 4 port mapping and serial port application
vs2013已阻止安装程序,需安装IE10
Great changes! National housing prices fell below the 10000 yuan mark
[RT thread] NXP rt10xx device driver framework -- RTC construction and use
One brush 145 force deduction hot question-2 sum of two numbers (m)
線程池:業務代碼最常用也最容易犯錯的組件
随机推荐
Wechat applet for the first time
大消费企业怎样做数字化转型?
【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用
Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
SVN如何查看修改的文件记录
Financial management (Higher Vocational College) financial management online Assignment 1 in autumn 20
Is AI too slow to design pictures and draw illustrations? 3 sets of practical brushes to save you
Analysis of variance summary
Electronic technology 20th autumn "Introduction to machine manufacturing" online assignment 3 [standard answer]
Free data | new library online | cnopendata complete data of China's insurance intermediary outlets
C language string inversion
線程池:業務代碼最常用也最容易犯錯的組件
One brush 148 force deduction hot question-5 longest palindrome substring (m)
[combinatorics] recursive equation (solution of linear non-homogeneous recursive equation with constant coefficients | standard form and general solution of recursive equation | proof of general solut
【RT-Thread】nxp rt10xx 设备驱动框架之--rtc搭建和使用
Where is the database account used when running SQL tasks in data warehouse tasks configured
C语言按行修改文件
University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
[combinatorics] recursive equation (characteristic equation and characteristic root | example of characteristic equation | root formula of monadic quadratic equation)
Thread pool: the most common and error prone component of business code