当前位置:网站首页>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
边栏推荐
- QT学习日记9——对话框
- Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“
- Kotlin learning quick start (7) -- wonderful use of expansion
- Kubernetes resource object introduction and common commands (V) - (NFS & PV & PVC)
- SVN完全备份svnadmin hotcopy
- Installation and configuration of network hard disk NFS
- kubernetes资源对象介绍及常用命令(四)
- [error reporting] omp: error 15: initializing libiomp5md dll, but found libiomp5md. dll already initialized.
- Pools de Threads: les composants les plus courants et les plus sujets aux erreurs du Code d'affaires
- Hongmeng third training
猜你喜欢

线程池:业务代码最常用也最容易犯错的组件

Analysis of variance summary

【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用
![[try to hack] active detection and concealment technology](/img/43/d48f851268fec566ce0cc83bd9557e.png)
[try to hack] active detection and concealment technology

Life is still confused? Maybe these subscription numbers have the answers you need!

UE4 official charging resources, with a total price of several thousand

Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing

kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)

Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos

One brush 145 force deduction hot question-2 sum of two numbers (m)
随机推荐
C language string inversion
VM11289 WAService. js:2 Do not have __ e handler in component:
Svn full backup svnadmin hotcopy
TensorBoard快速入门(Pytorch使用TensorBoard)
Applet setting multi account debugging
When absolutely positioned, the element is horizontally and vertically centered
Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
Loop through JSON object list
An example of HP array card troubleshooting
鸿蒙第三次培训
One brush 147-force deduction hot question-4 find the median of two positive arrays (H)
ANOVA example
Redis:关于列表List类型数据的操作命令
How to read the source code [debug and observe the source code]
Visual studio "usually, each socket address (Protocol / network address / port) can only be used once“
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
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
[combinatorics] recursive equation (special solution form | special solution solving method | special solution example)
UE4 official charging resources, with a total price of several thousand
Analysis of variance summary
https://www.bilibili.com/video/BV1g4411H78N?spm_id_from=333.337.search-card.all.click&vd_source=0471cde1c644648fafd07b54e303c905