一、字体对话框
Qt中提供了预定义的字体对话框QFontDialog类
QFontDialog类用于提供字体的对话框部件
字体对话框的使用方式
QfontDialog中的使用函数
QFontDialog::getFont
二、进度对话框
Qt 中提供了预定义的进度对话框QProgressDialog
QProgressDialog类用于显示进度信息
QProgressDialog类用于需要用户等待的场合
进度对话框的使用方式
三、编程实验 进度对话框使用实例21-1.pro
#include "Widget.h"
#include <QDebug>
#include <QPrinter>
#include <QTextDocument>
#include <QPrintDialog>
#include <QProgressDialog>
#include <QFontDialog>
Widget::Widget(QWidget *parent) : QWidget(parent),
FontDialogBtn(this), ProgressDialogBtn(this), PrintDialogBtn(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);
PrintDialogBtn.setText("Print Dialog");
PrintDialogBtn.move(20, 120);
PrintDialogBtn.resize(160, 30);
resize(200, 170);
setFixedSize(200, 170);
connect(&FontDialogBtn, SIGNAL(clicked()), this, SLOT(FontDialogBtn_Clicked()));
connect(&ProgressDialogBtn, SIGNAL(clicked()), this, SLOT(ProgressDialogBtn_Clicked()));
connect(&PrintDialogBtn, SIGNAL(clicked()), this, SLOT(PrintDialogBtn_Clicked()));
}
void Widget::FontDialogBtn_Clicked()
{
QFontDialog dlg(this);
dlg.setWindowTitle("Font Dialog Test");
dlg.setCurrentFont(QFont("Courier New", 10, QFont::Bold));
if( dlg.exec() == QFontDialog::Accepted )
{
qDebug() << dlg.selectedFont();
}
}
void Widget::ProgressDialogBtn_Clicked()
{
QProgressDialog dlg(this);
dlg.setWindowTitle("Updating...");
dlg.setLabelText("Downloading update from server...");
dlg.setMinimum(0);
dlg.setMaximum(100);
dlg.setValue(58);
// create a new thread
dlg.exec();
}
void Widget::PrintDialogBtn_Clicked()
{
QPrintDialog dlg(this);
dlg.setWindowTitle("Print Dialog Test");
if( dlg.exec() == QPrintDialog::Accepted )
{
QPrinter* p = dlg.printer();
QTextDocument td;
//td.setPlainText("Printer object test!");
td.setHtml("<h1>Print html object test</hl>");
p->setOutputFileName("D:\\test.xps");
td.print(p);
}
}
Widget::~Widget()
{
}
四、打印对话框
Qt中提供了预定义的打印对话框QPrintDialog类
QPrintDialog类用于设置打印相关的参数信息
打印对话框的使用方式
Qt中的QPrinter类是打印设备及其参数封装
QPrinter类封装了系统中打印设备的驱动接口
QPrinter以相同方式使用系统中的不同打印设备
五、小结
Qt标准对话框的设计模式
GUI界面部件产生的数据对象
业务逻辑中的其他对象使用数据对象
GUI界面与业务逻辑通过数据对象连接
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。