source: trunk/doc/src/printing.qdoc@ 321

Last change on this file since 321 was 2, checked in by Dmitry A. Kuminov, 16 years ago

Initially imported qt-all-opensource-src-4.5.1 from Trolltech.

File size: 8.0 KB
Line 
1/****************************************************************************
2**
3** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4** Contact: Qt Software Information ([email protected])
5**
6** This file is part of the documentation of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial Usage
10** Licensees holding valid Qt Commercial licenses may use this file in
11** accordance with the Qt Commercial License Agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and Nokia.
14**
15** GNU Lesser General Public License Usage
16** Alternatively, this file may be used under the terms of the GNU Lesser
17** General Public License version 2.1 as published by the Free Software
18** Foundation and appearing in the file LICENSE.LGPL included in the
19** packaging of this file. Please review the following information to
20** ensure the GNU Lesser General Public License version 2.1 requirements
21** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
22**
23** In addition, as a special exception, Nokia gives you certain
24** additional rights. These rights are described in the Nokia Qt LGPL
25** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
26** package.
27**
28** GNU General Public License Usage
29** Alternatively, this file may be used under the terms of the GNU
30** General Public License version 3.0 as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL included in the
32** packaging of this file. Please review the following information to
33** ensure the GNU General Public License version 3.0 requirements will be
34** met: http://www.gnu.org/copyleft/gpl.html.
35**
36** If you are unsure which license is appropriate for your use, please
37** contact the sales department at [email protected].
38** $QT_END_LICENSE$
39**
40****************************************************************************/
41
42/*!
43 \page printing.html
44 \title Printing with Qt
45 \ingroup multimedia
46 \ingroup text-processing
47 \brief A guide to producing printed output with Qt's paint system and widgets.
48
49 Qt provides extensive cross-platform support for printing. Using the printing
50 systems on each platform, Qt applications can print to attached printers and
51 across networks to remote printers. Qt's printing system also enables PostScript
52 and PDF files to be generated, providing the foundation for basic report
53 generation facilities.
54
55 \tableofcontents
56
57 \section1 Paint Devices and Printing
58
59 In Qt, printers are represented by QPrinter, a paint device that provides
60 functionality specific to printing, such as support for multiple pages and
61 double-sided output. As a result, printing involves using a QPainter to paint
62 onto a series of pages in the same way that you would paint onto a custom
63 widget or image.
64
65 \section2 Creating a QPrinter
66
67 Although QPrinter objects can be constructed and set up without requiring user
68 input, printing is often performed as a result of a request by the user;
69 for example, when the user selects the \gui{File|Print...} menu item in a GUI
70 application. In such cases, a newly-constructed QPrinter object is supplied to
71 a QPrintDialog, allowing the user to specify the printer to use, paper size, and
72 other printing properties.
73
74 \snippet examples/richtext/orderform/mainwindow.cpp 18
75
76 It is also possible to set certain default properties by modifying the QPrinter
77 before it is supplied to the print dialog. For example, applications that
78 generate batches of reports for printing may set up the QPrinter to
79 \l{QPrinter::setOutputFileName()}{write to a local file} by default rather than
80 to a printer.
81
82 \section2 Painting onto a Page
83
84 Once a QPrinter object has been constructed and set up, a QPainter can be used
85 to perform painting operations on it. We can construct and set up a painter in
86 the following way:
87
88 \snippet doc/src/snippets/printing-qprinter/object.cpp 0
89
90 Since the QPrinter starts with a blank page, we only need to call the
91 \l{QPrinter::}{newPage()} function after drawing each page, except for the
92 last page.
93
94 The document is sent to the printer, or written to a local file, when we call
95 \l{QPainter::}{end()}.
96
97 \section2 Coordinate Systems
98
99 QPrinter provides functions that can be used to obtain information about the
100 dimensions of the paper (the paper rectangle) and the dimensions of the
101 printable area (the page rectangle). These are given in logical device
102 coordinates that may differ from the physical coordinates used by the device
103 itself, indicating that the printer is able to render text and graphics at a
104 (typically higher) resolution than the user's display.
105
106 Although we do not need to handle the conversion between logical and physical
107 coordinates ourselves, we still need to apply transformations to painting
108 operations because the pixel measurements used to draw on screen are often
109 too small for the higher resolutions of typical printers.
110
111 \table
112 \row \o \bold{Printer and Painter Coordinate Systems}
113
114 The \l{QPrinter::}{paperRect()} and \l{QPrinter::}{pageRect()} functions
115 provide information about the size of the paper used for printing and the
116 area on it that can be painted on.
117
118 The rectangle returned by \l{QPrinter::}{pageRect()} usually lies inside
119 the rectangle returned by \l{QPrinter::}{paperRect()}. You do not need to
120 take the positions and sizes of these area into account when using a QPainter
121 with a QPrinter as the underlying paint device; the origin of the painter's
122 coordinate system will coincide with the top-left corner of the page
123 rectangle, and painting operations will be clipped to the bounds of the
124 drawable part of the page.
125
126 \o \inlineimage printer-rects.png
127 \endtable
128
129 The paint system automatically uses the correct device metrics when painting
130 text but, if you need to position text using information obtained from
131 font metrics, you need to ensure that the print device is specified when
132 you construct QFontMetrics and QFontMetricsF objects, or ensure that each QFont
133 used is constructed using the form of the constructor that accepts a
134 QPaintDevice argument.
135
136 \section1 Printing from Complex Widgets
137
138 Certain widgets, such as QTextEdit and QGraphicsView, display rich content
139 that is typically managed by instances of other classes, such as QTextDocument
140 and QGraphicsScene. As a result, it is these content handling classes that
141 usually provide printing functionality, either via a function that can be used
142 to perform the complete task, or via a function that accepts an existing
143 QPainter object. Some widgets provide convenience functions to expose underlying
144 printing features, avoiding the need to obtain the content handler just to call
145 a single function.
146
147 The following table shows which class and function are responsible for
148 printing from a selection of different widgets. For widgets that do not expose
149 printing functionality directly, the content handling classes containing this
150 functionality can be obtained via a function in the corresponding widget's API.
151
152 \table
153 \header \o Widget \o Printing function \o Accepts
154 \row \o QGraphicsView \o QGraphicsView::render() \o QPainter
155 \row \o QSvgWidget \o QSvgRenderer::render() \o QPainter
156 \row \o QTextEdit \o QTextDocument::print() \o QPrinter
157 \row \o QTextLayout \o QTextLayout::draw() \o QPainter
158 \row \o QTextLine \o QTextLine::draw() \o QPainter
159 \endtable
160
161 QTextEdit requires a QPrinter rather than a QPainter because it uses information
162 about the configured page dimensions in order to insert page breaks at the most
163 appropriate places in printed documents.
164*/
165
166/*!
167 \page pdf-licensing.html
168 \title Notes about PDF Licensing
169 \ingroup licensing
170 \brief Details of restrictions on the use of PDF-related trademarks.
171
172 Please note that Adobe\reg places restrictions on the use of its trademarks
173 (including logos) in conjunction with PDF; e.g. "Adobe PDF". Please refer
174 to \l{http://www.adobe.com}{www.adobe.com} for guidelines.
175*/
Note: See TracBrowser for help on using the repository browser.