当前位置:网站首页>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界面与业务逻辑通过数据对象连接
边栏推荐
- 【电脑插入U盘或者内存卡显示无法格式化FAT32如何解决】
- 实现CNN图像的识别和训练通过tensorflow框架对cifar10数据集等方法的处理
- 从零开始的基于百度大脑EasyData的多人协同数据标注
- Mysql:insert date:SQL 错误 [1292] [22001]: Data truncation: Incorrect date value:
- Unity EmbeddedBrowser浏览器插件事件通讯
- SQL Injection (GET/Search)
- Libuv库 - 设计概述(中文版)
- MapReduce implements matrix multiplication - implementation code
- windos 创建cordova 提示 因为在此系统上禁止运行脚本
- 掌握Cypress命令行选项,是真正掌握Cypress的基础
猜你喜欢
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Complete DNN deep neural network CNN training with tensorflow to complete image recognition cases
Unity EmbeddedBrowser浏览器插件事件通讯
Qt学习23 布局管理器(二)
Unable to stop it, domestic chips have made another breakthrough, and some links have reached 4nm
AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
Golang - command line tool Cobra
[quantitative trading] permanent portfolio, turtle trading rules reading, back testing and discussion
Kivy tutorial how to automatically load kV files
GoLand 2021.2 configure go (go1.17.6)
随机推荐
Dynamic programming 01 knapsack and complete knapsack
挡不住了,国产芯片再度突进,部分环节已进到4nm
Bidirectional linked list (we only need to pay attention to insert and delete functions)
Go 1.16.4: manage third-party libraries with Mod
[how to solve FAT32 when the computer is inserted into the U disk or the memory card display cannot be formatted]
怎样删除对象的某个属性或⽅法
SQL Injection (POST/Select)
pytorch 载入历史模型时更换gpu卡号,map_location设置
栈应用(平衡符)
Summary of common error reporting problems and positioning methods of thrift
AI scores 81 in high scores. Netizens: AI model can't avoid "internal examination"!
Go language web development series 27: Gin framework: using gin swagger to implement interface documents
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
MapReduce implements matrix multiplication - implementation code
Father and basketball
[understanding by chance-37]: the structure of human sensory system determines that human beings are self-centered
Swiftui development experience: the five most powerful principles that a programmer needs to master
windos 创建cordova 提示 因为在此系统上禁止运行脚本
Logback log sorting
There is nothing new under the sun. Can the meta universe go higher?