QPaintDevice Class
The QPaintDevice class is the base class of objects that can be painted on with QPainter. More...
Header: | #include <QPaintDevice> |
qmake: | QT += gui |
Inherited By: | QImage, QOpenGLPaintDevice, QPagedPaintDevice, QPaintDeviceWindow, QPicture, and QPixmap |
Public Types
enum | PaintDeviceMetric { PdmWidth, PdmHeight, PdmWidthMM, PdmHeightMM, ..., PdmDevicePixelRatioScaled } |
Public Functions
virtual | ~QPaintDevice() |
int | colorCount() const |
int | depth() const |
virtual int | devType() const |
int | devicePixelRatio() const |
qreal | devicePixelRatioF() const |
int | height() const |
int | heightMM() const |
int | logicalDpiX() const |
int | logicalDpiY() const |
virtual QPaintEngine * | paintEngine() const = 0 |
bool | paintingActive() const |
int | physicalDpiX() const |
int | physicalDpiY() const |
int | width() const |
int | widthMM() const |
Static Public Members
qreal | devicePixelRatioFScale() |
Protected Functions
QPaintDevice() | |
virtual int | metric(QPaintDevice::PaintDeviceMetric metric) const |
Protected Variables
ushort | painters |
Detailed Description
The QPaintDevice class is the base class of objects that can be painted on with QPainter.
A paint device is an abstraction of a two-dimensional space that can be drawn on using a QPainter. Its default coordinate system has its origin located at the top-left position. X increases to the right and Y increases downwards. The unit is one pixel.
The drawing capabilities of QPaintDevice are currently implemented by the QWidget, QImage, QPixmap, QGLPixelBuffer, QPicture, and QPrinter subclasses.
To implement support for a new backend, you must derive from QPaintDevice and reimplement the virtual paintEngine() function to tell QPainter which paint engine should be used to draw on this particular device. Note that you also must create a corresponding paint engine to be able to draw on the device, i.e derive from QPaintEngine and reimplement its virtual functions.
Warning: Qt requires that a QGuiApplication object exists before any paint devices can be created. Paint devices access window system resources, and these resources are not initialized before an application object is created.
The QPaintDevice class provides several functions returning the various device metrics: The depth() function returns its bit depth (number of bit planes). The height() function returns its height in default coordinate system units (e.g. pixels for QPixmap and QWidget) while heightMM() returns the height of the device in millimeters. Similiarily, the width() and widthMM() functions return the width of the device in default coordinate system units and in millimeters, respectively. Alternatively, the protected metric() function can be used to retrieve the metric information by specifying the desired PaintDeviceMetric as argument.
The logicalDpiX() and logicalDpiY() functions return the horizontal and vertical resolution of the device in dots per inch. The physicalDpiX() and physicalDpiY() functions also return the resolution of the device in dots per inch, but note that if the logical and physical resolution differ, the corresponding QPaintEngine must handle the mapping. Finally, the colorCount() function returns the number of different colors available for the paint device.
See also QPaintEngine, QPainter, Coordinate System, and Paint System.
Member Type Documentation
enum QPaintDevice::PaintDeviceMetric
Describes the various metrics of a paint device.
Constant | Value | Description |
---|---|---|
QPaintDevice::PdmWidth | 1 | The width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget). See also width(). |
QPaintDevice::PdmHeight | 2 | The height of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget). See also height(). |
QPaintDevice::PdmWidthMM | 3 | The width of the paint device in millimeters. See also widthMM(). |
QPaintDevice::PdmHeightMM | 4 | The height of the paint device in millimeters. See also heightMM(). |
QPaintDevice::PdmNumColors | 5 | The number of different colors available for the paint device. See also colorCount(). |
QPaintDevice::PdmDepth | 6 | The bit depth (number of bit planes) of the paint device. See also depth(). |
QPaintDevice::PdmDpiX | 7 | The horizontal resolution of the device in dots per inch. See also logicalDpiX(). |
QPaintDevice::PdmDpiY | 8 | The vertical resolution of the device in dots per inch. See also logicalDpiY(). |
QPaintDevice::PdmPhysicalDpiX | 9 | The horizontal resolution of the device in dots per inch. See also physicalDpiX(). |
QPaintDevice::PdmPhysicalDpiY | 10 | The vertical resolution of the device in dots per inch. See also physicalDpiY(). |
QPaintDevice::PdmDevicePixelRatio | 11 | The device pixel ratio for device. Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" displays. |
QPaintDevice::PdmDevicePixelRatioScaled | 12 | The scaled device pixel ratio for the device. This is identical to PdmDevicePixelRatio, except that the value is scaled by a constant factor in order to support paint devices with fractional scale factors. The constant scaling factor used is devicePixelRatioFScale(). This enum value has been introduced in Qt 5.6. |
See also metric() and devicePixelRatioF().
Member Function Documentation
[protected]
QPaintDevice::QPaintDevice()
Default constructs an instance of QPaintDevice.
[virtual]
QPaintDevice::~QPaintDevice()
Destroys the instance of QPaintDevice. The destructor is virtual.