Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
qpaintdevice.qdoc
Go to the documentation of this file.
1// Copyright (C) 2016 The Qt Company Ltd.
2// SPDX-License-Identifier: LicenseRef-Qt-Commercial OR GFDL-1.3-no-invariants-only
3
4/*!
5 \class QPaintDevice
6 \brief The QPaintDevice class is the base class of objects that
7 can be painted on with QPainter.
8
9 \ingroup painting
10 \inmodule QtGui
11
12 A paint device is an abstraction of a two-dimensional space that
13 can be drawn on using a QPainter. Its default coordinate system has
14 its origin located at the top-left position. X increases to the
15 right and Y increases downwards. The unit is one pixel.
16
17 The drawing capabilities of QPaintDevice are currently implemented
18 by the QWidget, QImage, QPixmap, QPicture, and QPrinter subclasses.
19
20 To implement support for a new backend, you must derive from
21 QPaintDevice and reimplement the virtual paintEngine() function to
22 tell QPainter which paint engine should be used to draw on this
23 particular device. Note that you also must create a corresponding
24 paint engine to be able to draw on the device, i.e derive from
25 QPaintEngine and reimplement its virtual functions.
26
27 \warning Qt requires that a QGuiApplication object exists before
28 any paint devices can be created. Paint devices access window
29 system resources, and these resources are not initialized before
30 an application object is created.
31
32 The QPaintDevice class provides several functions returning the
33 various device metrics: The depth() function returns its bit depth
34 (number of bit planes). The height() function returns its height
35 in default coordinate system units (e.g. pixels for QPixmap and
36 QWidget) while heightMM() returns the height of the device in
37 millimeters. Similiarily, the width() and widthMM() functions
38 return the width of the device in default coordinate system units
39 and in millimeters, respectively. Alternatively, the protected
40 metric() function can be used to retrieve the metric information
41 by specifying the desired PaintDeviceMetric as argument.
42
43 The logicalDpiX() and logicalDpiY() functions return the
44 horizontal and vertical resolution of the device in dots per
45 inch. The physicalDpiX() and physicalDpiY() functions also return
46 the resolution of the device in dots per inch, but note that if
47 the logical and physical resolution differ, the corresponding
48 QPaintEngine must handle the mapping. Finally, the colorCount()
49 function returns the number of different colors available for the
50 paint device.
51
52 \sa QPaintEngine, QPainter, {Coordinate System}, {Paint System}
53*/
54
55/*!
56 \enum QPaintDevice::PaintDeviceMetric
57
58 Describes the various metrics of a paint device.
59
60 \value PdmWidth The width of the paint device in default
61 coordinate system units (e.g. pixels for QPixmap and QWidget). See
62 also width().
63
64 \value PdmHeight The height of the paint device in default
65 coordinate system units (e.g. pixels for QPixmap and QWidget). See
66 also height().
67
68 \value PdmWidthMM The width of the paint device in millimeters. See
69 also widthMM().
70
71 \value PdmHeightMM The height of the paint device in millimeters. See
72 also heightMM().
73
74 \value PdmNumColors The number of different colors available for
75 the paint device. See also colorCount().
76
77 \value PdmDepth The bit depth (number of bit planes) of the paint
78 device. See also depth().
79
80 \value PdmDpiX The horizontal resolution of the device in dots per
81 inch. See also logicalDpiX().
82
83 \value PdmDpiY The vertical resolution of the device in dots per inch. See
84 also logicalDpiY().
85
86 \value PdmPhysicalDpiX The horizontal resolution of the device in
87 dots per inch. See also physicalDpiX().
88
89 \value PdmPhysicalDpiY The vertical resolution of the device in
90 dots per inch. See also physicalDpiY().
91
92 \value PdmDevicePixelRatio The device pixel ratio for device. Common
93 values are 1 for normal-dpi displays and 2 for high-dpi "retina"
94 displays.
95
96 \value PdmDevicePixelRatioScaled The scaled device pixel ratio for the device.
97 This is identical to PdmDevicePixelRatio, except that the value is scaled by a
98 constant factor in order to support paint devices with fractional scale factors.
99 The constant scaling factor used is devicePixelRatioFScale(). This enum value
100 has been introduced in Qt 5.6.
101
102 \value [since 6.8] PdmDevicePixelRatioF_EncodedA This enum item, together with the
103 corresponding \c B item, are used together for the device pixel ratio of the device, as an
104 encoded \c double floating point value. A QPaintDevice subclass that supports \e fractional DPR
105 values should implement support for these two enum items in its override of the metric()
106 function. The return value is expected to be the result of the encodeMetricF() function.
107
108 \value [since 6.8] PdmDevicePixelRatioF_EncodedB See PdmDevicePixelRatioF_EncodedA.
109
110 \sa metric(), devicePixelRatio()
111*/
112
113/*!
114 \fn QPaintDevice::QPaintDevice()
115
116 Constructs a paint device. This constructor can be invoked only from
117 subclasses of QPaintDevice.
118*/
119
120/*!
121 \fn QPaintDevice::~QPaintDevice()
122
123 Destroys the paint device and frees window system resources.
124*/
125
126/*!
127 \fn int QPaintDevice::devType() const
128
129 \internal
130
131 Returns the device type identifier, which is QInternal::Widget
132 if the device is a QWidget, QInternal::Pixmap if it's a
133 QPixmap, QInternal::Printer if it's a QPrinter,
134 QInternal::Picture if it's a QPicture, or
135 QInternal::UnknownDevice in other cases.
136*/
137
138/*!
139 \fn bool QPaintDevice::paintingActive() const
140
141 Returns \c true if the device is currently being painted on, i.e. someone has
142 called QPainter::begin() but not yet called QPainter::end() for
143 this device; otherwise returns \c false.
144
145 \sa QPainter::isActive()
146*/
147
148/*!
149 \fn QPaintEngine *QPaintDevice::paintEngine() const
150
151 Returns a pointer to the paint engine used for drawing on the
152 device.
153*/
154
155/*!
156 \fn int QPaintDevice::metric(PaintDeviceMetric metric) const
157
158 Returns the metric information for the given paint device \a metric.
159
160 \sa PaintDeviceMetric
161*/
162
163/*!
164 \fn int QPaintDevice::width() const
165
166 Returns the width of the paint device in default coordinate system
167 units (e.g. pixels for QPixmap and QWidget).
168
169 \sa widthMM()
170*/
171
172/*!
173 \fn int QPaintDevice::height() const
174
175 Returns the height of the paint device in default coordinate
176 system units (e.g. pixels for QPixmap and QWidget).
177
178 \sa heightMM()
179*/
180
181/*!
182 \fn int QPaintDevice::widthMM() const
183
184 Returns the width of the paint device in millimeters. Due to platform
185 limitations it may not be possible to use this function to determine
186 the actual physical size of a widget on the screen.
187
188 \sa width()
189*/
190
191/*!
192 \fn int QPaintDevice::heightMM() const
193
194 Returns the height of the paint device in millimeters. Due to platform
195 limitations it may not be possible to use this function to determine
196 the actual physical size of a widget on the screen.
197
198 \sa height()
199*/
200
201/*!
202 \fn int QPaintDevice::colorCount() const
203
204 Returns the number of different colors available for the paint
205 device. If the number of colors available is too great to be
206 represented by the int data type, then INT_MAX will be returned
207 instead.
208*/
209
210/*!
211 \fn int QPaintDevice::depth() const
212
213 Returns the bit depth (number of bit planes) of the paint device.
214*/
215
216/*!
217 \fn int QPaintDevice::logicalDpiX() const
218
219 Returns the horizontal resolution of the device in dots per inch,
220 which is used when computing font sizes. For X11, this is usually
221 the same as could be computed from widthMM().
222
223 Note that if the logicalDpiX() doesn't equal the physicalDpiX(),
224 the corresponding QPaintEngine must handle the resolution mapping.
225
226 \sa logicalDpiY(), physicalDpiX()
227*/
228
229/*!
230 \fn int QPaintDevice::logicalDpiY() const
231
232 Returns the vertical resolution of the device in dots per inch,
233 which is used when computing font sizes. For X11, this is usually
234 the same as could be computed from heightMM().
235
236 Note that if the logicalDpiY() doesn't equal the physicalDpiY(),
237 the corresponding QPaintEngine must handle the resolution mapping.
238
239 \sa logicalDpiX(), physicalDpiY()
240*/
241
242/*!
243 \fn int QPaintDevice::physicalDpiX() const
244
245 Returns the horizontal resolution of the device in dots per inch.
246 For example, when printing, this resolution refers to the physical
247 printer's resolution. The logical DPI on the other hand, refers to
248 the resolution used by the actual paint engine.
249
250 Note that if the physicalDpiX() doesn't equal the logicalDpiX(),
251 the corresponding QPaintEngine must handle the resolution mapping.
252
253 \sa physicalDpiY(), logicalDpiX()
254*/
255
256/*!
257 \fn int QPaintDevice::physicalDpiY() const
258
259 Returns the horizontal resolution of the device in dots per inch.
260 For example, when printing, this resolution refers to the physical
261 printer's resolution. The logical DPI on the other hand, refers to
262 the resolution used by the actual paint engine.
263
264 Note that if the physicalDpiY() doesn't equal the logicalDpiY(),
265 the corresponding QPaintEngine must handle the resolution mapping.
266
267 \sa physicalDpiX(), logicalDpiY()
268*/
269
270/*!
271 \fn qreal QPaintDevice::devicePixelRatio() const
272
273 Returns the device pixel ratio for device.
274
275 Common values are 1 for normal-dpi displays and 2 for high-dpi
276 "retina" displays.
277*/
278
279/*!
280 \fn qreal QPaintDevice::devicePixelRatioF() const
281
282 Returns the device pixel ratio for the device as a floating point number.
283
284 \since 5.6
285*/
286
287/*!
288 \fn qreal QPaintDevice::devicePixelRatioFScale()
289
290 \internal
291
292 Returns the scaling factor used for \c PdmDevicePixelRatioScaled. Classes
293 that are not QPaintDevice subclasses are implementing metric(), and need to
294 access this constant. Since it's a qreal, it cannot be an enum, and an inline
295 function is more efficient than a static member variable.
296
297 \since 5.6
298*/
299
300/*!
301 \fn int QPaintDevice::encodeMetricF(PaintDeviceMetric metric, double value)
302
303 Returns \a value encoded for the metric \a metric. Subclasses implementing metric() should use
304 this function to encode \value as an integer return value when the query metric specifies an
305 encoded floating-point value.
306
307 \since 6.8
308*/