内容提要:
QPainter 可以在任何“绘图设备”(继承自QPaintDevice的类)上进行绘画,例如:QWidget、QPixmap、QImage、QSvgGenerator等。要想在绘图设备上绘图,只需创建一个QPainter对象,再将指针传到该设备中即可在该设备的paintEvent中进行绘画。
1,Qt导出文件的基本原理;
2,QPrinter、HTML和PDF;
3,HTML编辑器;
4,HTML和Word;
5,qwt的图片和pdf导出
一、Qt绘图和导出文件的基本原理
Qt的二维图形引擎是基于QPainter类的。QPainter既可以绘制几何形状(点、线、矩形、椭圆、弧形、弦行、饼状图、多边形和贝塞尔曲线),也可以绘制像素映射、图像和文字。(参考《C++ GUI Programming with Qt》)
查看Qt的帮助文档,关于“QPainter”的描述:
The QPainter class performs low-level painting on widgets and other paint devices.
QPainter provides highly optimized functions to do most of the drawing GUI programs require. It can draw everything from simple lines to complex shapes like pies and chords. It can also draw aligned text and pixmaps. Normally, it draws in a "natural" coordinate system, but it can also do view and world transformation. QPainter can operate on any object that inherits the QPaintDevice class.
The common use of QPainter is inside a widget's paint event: Construct and customize (e.g. set the pen or the brush) the painter. Then draw. Remember to destroy the QPainter object after drawing.
QPainter也可以与QPrinter一起使用来打印文件和创建PDF文档。查看Qt的帮助文档,关于“QPrinter”的描述如下:
The QPrinter class is a paint device that paints on a printer.
This device represents a series of pages of printed output, and is used in almost exactly the same way as other paint devices such as QWidget and QPixmap. A set of additional functions are provided to manage device-specific features, such as orientation and resolution, and to step through the pages in a document as it is generated.
QPrinter
本质上也是一个绘图设备,在QPrinter上绘图和在其他设备上绘图的方法非常类似,不同的是一些设备相关的管理函数。
(参考《C++ GUI Programming with Qt》和
Qt之生成PDF
)QPrinter可以设置两种输出格式:
QPrinter::NativeFormat和
QPrinter::PdfFormat,前一种是直接打印,后一种是导出为pdf文档。
二、
QPrinter导出PDF