当前位置:网站首页>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、选择的文件路径
边栏推荐
- Build your own website (23)
- RDS数据库的监测页面在哪看?
- Redis: operation commands for list type data
- Atom QT 16_ audiorecorder
- Collection of the most beautiful graduation photos in the graduation season, collection of excellent graduation photos
- C语言按行修改文件
- 在iptables防火墙下开启vsftpd的端口
- 人生还在迷茫?也许这些订阅号里有你需要的答案!
- 【Try to Hack】主动侦查隐藏技术
- Static program analysis (I) -- Outline mind map and content introduction
猜你喜欢
鸿蒙第三次培训
UCORE overview
Cross border e-commerce: advantages of foreign trade enterprises in overseas social media marketing
Select 3 fcpx plug-ins. Come and see if you like them
How do large consumer enterprises make digital transformation?
C语言按行修改文件
Bcvp developer community 2022 exclusive peripheral first bullet
[JDBC] API parsing
Redis:关于列表List类型数据的操作命令
kubernetes资源对象介绍及常用命令(四)
随机推荐
Apache service suspended asynchronous acceptex failed
Play with fancy special effects. This AE super kit is for you
鸿蒙第三次培训
The most complete postman interface test tutorial in the whole network, API interface test
Select 3 fcpx plug-ins. Come and see if you like them
Design e-commerce spike
图之深度优先搜索
Squid service startup script
When absolutely positioned, the element is horizontally and vertically centered
LeetCode13.罗马数字转整数(三种解法)
Leetcode: lucky number in matrix
RedHat 6.2 配置 Zabbix
PHP online confusion encryption tutorial sharing + basically no solution
数仓任务里面 跑SQL任务的时候用的数据库账号是在哪里配置的
线程池:业务代码最常用也最容易犯错的组件
新库上线 | CnOpenData中国观鸟记录数据
HP 阵列卡排障一例
Redis:关于列表List类型数据的操作命令
Where is the database account used when running SQL tasks in data warehouse tasks configured
One brush 144 force deduction hot question-1 sum of two numbers (E)