当前位置:网站首页>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界面与业务逻辑通过数据对象连接
边栏推荐
- [quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
- The network card fails to start after the cold migration of the server hard disk
- mysql中的字段问题
- SwiftUI 开发经验之作为一名程序员需要掌握的五个最有力的原则
- Mobile phones and computers can be used, whole people, spoof code connections, "won't you Baidu for a while" teach you to use Baidu
- Halcon combined with C # to detect surface defects -- Halcon routine autobahn
- [how to earn a million passive income]
- 【BW16 应用篇】安信可BW16模组与开发板更新固件烧录说明
- PHP maze game
- Logback log sorting
猜你喜欢
Logback log sorting
Go language web development series 25: Gin framework: using MD5 to verify the signature for the interface station
太阳底下无新事,元宇宙能否更上层楼?
[bw16 application] instructions for firmware burning of Anxin Ke bw16 module and development board update
Kivy tutorial how to automatically load kV files
Resource Cost Optimization Practice of R & D team
8 Queen question
Flutter动态化 | Fair 2.5.0 新版本特性
SQL Injection (GET/Search)
Bidirectional linked list (we only need to pay attention to insert and delete functions)
随机推荐
Thrift threadmanager and three monitors
Spark practice 1: build spark operation environment in single node local mode
CVPR 2022 | 美团技术团队精选6篇优秀论文解读
Screenshot of the operation steps of upload labs level 4-level 9
Universal dividend source code, supports the dividend of any B on the BSC
Resource Cost Optimization Practice of R & D team
Kivy教程之 盒子布局 BoxLayout将子项排列在垂直或水平框中(教程含源码)
实现CNN图像的识别和训练通过tensorflow框架对cifar10数据集等方法的处理
ThreadPoolExecutor realizes multi-threaded concurrency and obtains the return value (elegant and concise way)
Halcon combined with C # to detect surface defects -- Halcon routine autobahn
从零开始的基于百度大脑EasyData的多人协同数据标注
8 Queen question
MySQL 数据处理值增删改
Golang — template
Unity Render Streaming通过Js与Unity自定义通讯
Kivy tutorial how to automatically load kV files
【556. 下一个更大元素 III】
Box layout of Kivy tutorial BoxLayout arranges sub items in vertical or horizontal boxes (tutorial includes source code)
Another industry has been broken by Chinese chips. No wonder the leading analog chip companies in the United States have cut prices and sold off
【被动收入如何挣个一百万】