当前位置:网站首页>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界面与业务逻辑通过数据对象连接

边栏推荐
- Implementation of Muduo accept connection, disconnection and sending data
- [技術發展-24]:現有物聯網通信技術特點
- Brief analysis of tensorboard visual processing cases
- 使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
- Shell timing script, starting from 0, CSV format data is regularly imported into PostgreSQL database shell script example
- 使用Tensorflow进行完整的深度神经网络CNN训练完成图片识别案例2
- php 迷宫游戏
- SQL Injection (POST/Search)
- Red hat satellite 6: better management of servers and clouds
- Leetcode-1175. Prime Arrangements
猜你喜欢

MySQL 数据处理值增删改

Flutter动态化 | Fair 2.5.0 新版本特性

【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明

Using registered classes to realize specific type matching function template

Qt学习20 Qt 中的标准对话框(中)

刚毕业的欧洲大学生,就能拿到美国互联网大厂 Offer?

There is nothing new under the sun. Can the meta universe go higher?
![[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]](/img/95/09552d33d2a834af4d304129714775.png)
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]

Common network state detection and analysis tools

双向链表(我们只需要关注插入和删除函数)
随机推荐
全面发展数字经济主航道 和数集团积极推动UTONMOS数藏市场
NFT new opportunity, multimedia NFT aggregation platform okaleido will be launched soon
又一个行业被中国芯片打破空白,难怪美国模拟芯片龙头降价抛售了
研发团队资源成本优化实践
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
使用tensorflow进行完整的DNN深度神经网络CNN训练完成图片识别案例
Kivy教程之 如何自动载入kv文件
Complete deep neural network CNN training with tensorflow to complete picture recognition case 2
Halcon combined with C # to detect surface defects -- Halcon routine autobahn
Richview trvstyle liststyle list style (bullet number)
Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
网上开户哪家证券公司佣金最低,我要开户,网上客户经理开户安全吗
Go language web development series 28: solve cross domain access of CORS with gin contrib / CORS
Red hat satellite 6: better management of servers and clouds
SQL Injection (POST/Search)
When updating mysql, the condition is a query
[556. Next larger element III]
树的深入和广度优先遍历(不考虑二叉树)
记录关于银行回调post请求405 问题
Ocean CMS vulnerability - search php