当前位置:网站首页>Qt学习21 Qt 中的标准对话框(下)
Qt学习21 Qt 中的标准对话框(下)
2022-07-03 13:23:00 【一个小黑酱】
Qt学习21 Qt 中的标准对话框(下)
字体对话框
- Qt中提供了预定义的字体对话框QFontDialog类
- QFontDialog类用于提供选择字体的对话框部件

- 字体对话框的使用方式
// 构造字体对话框对象
QFontDialog dlg(this);
// 设置字体对话框的相关属性
dlg.setWindowTitle("Font Editor");
dlg.setCurrentFont(QFont("Courier New", 10, QFont::Bold)); // 初始字体
if (dlg.exec() == QFontDialog::Accepted) {
qDebug() << dlg.selectedFont();
}
- QFontDialog中的实用函数
- QFontDialog::getFont
进度对话框
- Qt中提供了预定义的进度对话框QProgressDialog类
- QProgressDialog类用于显示进度信息
- QProgressDialog类用于需要用户等待的场合

- 进度对话框的使用方式
// 构造进度对话框对象
QProgressDialog dlg(this);
// 设置进度对话框的相关属性
dlg.setWindowTitle("Updating...");
dlg.setLabelText("Downloading from server...");
dlg.setMinimum(0); // 设置最小进度值
dlg.setMaximum(1000); // 设置最大进度值
dlg.exec();
代码实验
#ifndef WIDGET_H
#define WIDGET_H
#include <QWidget>
#include <QPushButton>
class Widget : public QWidget
{
Q_OBJECT
private:
QPushButton FontDialogBtn;
QPushButton ProgressDialogBtn;
private slots:
void FontDialogBtn_Clicked();
void ProgressDialogBtn_Clicked();
public:
Widget(QWidget *parent = 0);
~Widget();
};
#endif // WIDGET_H
#include "Widget.h"
#include <QFontDialog>
#include <QProgressDialog>
#include <QDebug>
Widget::Widget(QWidget *parent)
: QWidget(parent), FontDialogBtn(this), ProgressDialogBtn(this)
{
FontDialogBtn.setText("Font Dialog");
FontDialogBtn.move(20, 20);
FontDialogBtn.resize(160, 30);
ProgressDialogBtn.setText("Progress Dialog");
ProgressDialogBtn.move(20, 70);
ProgressDialogBtn.resize(160, 30);
resize(200, 120);
setFixedSize(200, 120);
connect(&FontDialogBtn, SIGNAL(clicked()), this, SLOT(FontDialogBtn_Clicked()));
connect(&ProgressDialogBtn, SIGNAL(clicked()), this, SLOT(ProgressDialogBtn_Clicked()));
}
Widget::~Widget()
{
}
void Widget::FontDialogBtn_Clicked()
{
QFontDialog dlg(this);
dlg.setWindowTitle("Font Dialog Test");
dlg.setCurrentFont(QFont("Courier New", 10, QFont::Normal));
if (dlg.exec() == QFontDialog::Accepted) {
qDebug() << dlg.selectedFont();
}
// 简便用法
bool ok;
QFont font= QFont("Courier New", 10, QFont::Normal);
font = QFontDialog::getFont(&ok, font, this);
qDebug() << font;
}
void Widget::ProgressDialogBtn_Clicked()
{
QProgressDialog dlg(this);
dlg.setWindowTitle("Updating...");
dlg.setLabelText("Downloading update from server...");
dlg.setMinimum(0);
dlg.setMaximum(100);
dlg.setValue(35);
// create a new thread
dlg.exec();
}
#include "Widget.h"
#include <QApplication>
int main(int argc, char *argv[])
{
QApplication a(argc, argv);
Widget w;
w.show();
return a.exec();
}
小结
- Qt中标准对话框的设计模式
- GUI界面部件产生数据对象
- 业务逻辑中的其他对象使用数据对象
- GUI界面与业务逻辑通过数据对象连接

边栏推荐
- [556. Next larger element III]
- Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
- 8 Queen question
- CVPR 2022 | 美团技术团队精选6篇优秀论文解读
- pytorch 载入历史模型时更换gpu卡号,map_location设置
- Use and design of Muduo buffer class
- Flutter dynamic | fair 2.5.0 new version features
- Error handling when adding files to SVN:.... \conf\svnserve conf:12: Option expected
- SQL Injection (POST/Search)
- 解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
猜你喜欢

GoLand 2021.1: rename the go project

SQL Injection (GET/Search)
![[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心](/img/06/b71b505c7072d540955fda6da1dc1b.jpg)
[机缘参悟-37]:人感官系统的结构决定了人类是以自我为中心

又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了

Go language web development series 27: Gin framework: using gin swagger to implement interface documents

When updating mysql, the condition is a query

解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)

Golang — 命令行工具cobra

CVPR 2022 | 美团技术团队精选6篇优秀论文解读

There is nothing new under the sun. Can the meta universe go higher?
随机推荐
Go language unit test 5: go language uses go sqlmock and Gorm to do database query mock
PHP maze game
C language standard IO function sorting
Internet of things completion -- (stm32f407 connects to cloud platform detection data)
静态链表(数组的下标代替指针)
Qt学习18 登录对话框实例分析
The solution of Chinese font garbled code in keil5
CVPR 2022 | interpretation of 6 excellent papers selected by meituan technical team
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
Kivy tutorial how to automatically load kV files
Ocean CMS vulnerability - search php
MapReduce implements matrix multiplication - implementation code
解决MySql 1045 Access denied for user ‘root‘@‘localhost‘ (using password: YES)
Flutter动态化 | Fair 2.5.0 新版本特性
The latest BSC can pay dividends. Any B usdt Shib eth dividend destruction marketing can
刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?
Swiftui development experience: the five most powerful principles that a programmer needs to master
Students who do not understand the code can also send their own token, which is easy to learn BSC
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
Leetcode-1175.Prime Arrangements