当前位置:网站首页>QT学习日记9——对话框
QT学习日记9——对话框
2022-07-03 17:16:00 【herb.dr】
学习视频链接
目录
一、自定义对话框
1.1 模态对话框:
不可以对其他窗口进行操作
1.2 非模态对话框:
可以对其他的窗口进行操作
1.3 案例
下图是非模态对话框

在界面中打开窗口后,可以对原来的界面进行修改
模态对话框
运行弹窗的时候,函数阻塞在 dlg.exec(); 这行代码这里,点击 X 后,输出 QDebug

创建非模态对话框

函数是不会阻塞在 dlg2->show(); 这句话这里,因为防止一闪而过,所以创建到堆区
同时我们要注意,这个函数申请内存后,没有释放内存,可能后面会出现内存泄漏
我们需要在 X 掉窗口的时候顺便释放内存,加入中间那行代码

二、系统提供好的对话框
2.1 标准对话框
所谓标准对话框,是 Qt 内置的一系列对话框,用于简化开发。事实上,有很多对话框都是通用的,比如打开文件、设置颜色、打印设置等。这些对话框在所有程序中几乎相同,因此没有必要在每一个程序中都自己实现这么一个对话框
Qt 的内置对话框大致分为以下几类:
QColorDialog:选择颜色
FileDialog:选择文件或者目录
FontDialog:选择字体
QInputDialog:允许用户输入一个值,并将其值返回
QMessageBox:模态对话框,用于显示信息、询问问题等
QPageSetupDialog:为打印机提供纸张相关的选项
QPrintDialog:打印机配置
QPrintPreviewDialog:打印预览
ProgressDialog:显示操作过程
2.2 消息对话框

2.3 颜色对话框

点击OK以后,函数得到返回值,并且跳转进主窗口

注意:
1、2.2 和 2.3 的函数可以写在 connect 里面
#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, [](){
// 警告对话框
// QMessageBox::warning(this, "warning", "警告");
// 其他标准对话框
// 颜色对话框
QColor color = QColorDialog::getColor(QColor(255, 0, 0));
qDebug() << "r = " << color.red() << " g = " << color.green() << " b = " << color.blue();
});
}
MainWindow::~MainWindow()
{
delete ui;
}2、 颜色对话框 QColor(255, 0, 0, 255) 还有第四个参数,默认是 255 也就是四个参数
2.4 文件对话框
传入参数:
this:父亲
...:标题
...:默认的打开路径
...:要打开的格式(过滤其他格式)
返回值:
Qstring、选择的文件路径
边栏推荐
- Kubernetes resource object introduction and common commands (4)
- Bcvp developer community 2022 exclusive peripheral first bullet
- A day's work list of an ordinary programmer
- [combinatorics] recursive equation (constant coefficient linear homogeneous recursive equation | constant coefficient, linear, homogeneous concept description | constant coefficient linear homogeneous
- Thread pool: the most common and error prone component of business code
- RedHat 6.2 配置 Zabbix
- Dagong 21 autumn "power plant electrical part" online operation 1 [standard answer] power plant electrical part
- How to allow remote connection to MySQL server on Linux system?
- [combinatorics] recursive equation (general solution structure of recursive equation with multiple roots | linear independent solution | general solution with multiple roots | solution example of recu
- Golang单元测试、Mock测试以及基准测试
猜你喜欢

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

Atom QT 16_ audiorecorder

Redis: operation commands for list type data

建立自己的网站(23)

One brush 149 force deduction hot question-10 regular expression matching (H)
![Luogu: p2685 [tjoi2012] Bridge](/img/f5/f77027288a211ae466781b09ce650f.jpg)
Luogu: p2685 [tjoi2012] Bridge

【RT-Thread】nxp rt10xx 设备驱动框架之--hwtimer搭建和使用

【RT-Thread】nxp rt10xx 设备驱动框架之--Audio搭建和使用

Free data | new library online | cnopendata complete data of China's insurance intermediary outlets

New features of C 10
随机推荐
C language modifies files by line
Meituan side: why does thread crash not cause JVM crash
SVN如何查看修改的文件记录
kubernetes资源对象介绍及常用命令(五)-(NFS&PV&PVC)
University of Electronic Science and technology, accounting computerization, spring 20 final exam [standard answer]
Squid service startup script
UE4 official charging resources, with a total price of several thousand
Test your trained model
【Try to Hack】主动侦查隐藏技术
29:第三章:开发通行证服务:12:开发【获得用户账户信息,接口】;(使用VO类包装查到的数据,以符合接口对返回数据的要求)(在多处都会用到的逻辑,在Controller中可以把其抽成一个共用方法)
聊聊接口优化的几个方法
Analysis of variance summary
Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing
Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
[RT thread] NXP rt10xx device driver framework -- Audio construction and use
Unity notes unityxr simple to use
Why is WPA3 security of enterprise business so important?
How to allow remote connection to MySQL server on Linux system?
[2. Basics of Delphi grammar] 1 Identifiers and reserved words
Assignment examination questions of advanced English (III) for the course examination of Fujian Normal University in February 2022
https://www.bilibili.com/video/BV1g4411H78N?spm_id_from=333.337.search-card.all.click&vd_source=0471cde1c644648fafd07b54e303c905