QPaintDevice 类

QPaintDevice class is the base class of objects that can be painted on with QPainter . 更多...

Header: #include <QPaintDevice>
qmake: QT += gui
继承者:

QImage , QOpenGLPaintDevice , QPagedPaintDevice , QPaintDeviceWindow , QPicture ,和 QPixmap

公共类型

enum PaintDeviceMetric { PdmWidth, PdmHeight, PdmWidthMM, PdmHeightMM, ..., PdmDevicePixelRatioScaled }

公共函数

virtual ~QPaintDevice ()
int colorCount () const
int depth () 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

保护函数

QPaintDevice ()
virtual int metric (QPaintDevice::PaintDeviceMetric metric ) const

Protected Variables

ushort painters

详细描述

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.

警告: 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.

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 () 和 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 作为自变量。

logicalDpiX () 和 logicalDpiY () functions return the horizontal and vertical resolution of the device in dots per inch. The physicalDpiX () 和 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.

另请参阅 QPaintEngine , QPainter , 坐标系统 ,和 描绘系统 .

成员类型文档编制

enum QPaintDevice:: PaintDeviceMetric

Describes the various metrics of a paint device.

常量 描述
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.

另请参阅 metric () 和 devicePixelRatioF ().

成员函数文档编制

[protected] QPaintDevice:: QPaintDevice ()

Constructs a paint device. This constructor can be invoked only from subclasses of QPaintDevice .

[virtual] QPaintDevice:: ~QPaintDevice ()

Destroys the paint device and frees window system resources.

int QPaintDevice:: colorCount () const

Returns the number of different colors available for the paint device. If the number of colors available is too great to be represented by the int data type, then INT_MAX will be returned instead.

int QPaintDevice:: depth () const

Returns the bit depth (number of bit planes) of the paint device.

int QPaintDevice:: devicePixelRatio () const

Returns the device pixel ratio for device.

Common values are 1 for normal-dpi displays and 2 for high-dpi "retina" displays.

qreal QPaintDevice:: devicePixelRatioF () const

Returns the device pixel ratio for the device as a floating point number.

This function was introduced in Qt 5.6.

int QPaintDevice:: height () const

Returns the height of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget ).

另请参阅 heightMM ().

int QPaintDevice:: heightMM () const

Returns the height of the paint device in millimeters. Due to platform limitations it may not be possible to use this function to determine the actual physical size of a widget on the screen.

另请参阅 height ().

int QPaintDevice:: logicalDpiX () const

Returns the horizontal resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from widthMM ().

Note that if the logicalDpiX() doesn't equal the physicalDpiX (), the corresponding QPaintEngine must handle the resolution mapping.

另请参阅 logicalDpiY () 和 physicalDpiX ().

int QPaintDevice:: logicalDpiY () const

Returns the vertical resolution of the device in dots per inch, which is used when computing font sizes. For X11, this is usually the same as could be computed from heightMM ().

Note that if the logicalDpiY() doesn't equal the physicalDpiY (), the corresponding QPaintEngine must handle the resolution mapping.

另请参阅 logicalDpiX () 和 physicalDpiY ().

[virtual protected] int QPaintDevice:: metric ( QPaintDevice::PaintDeviceMetric metric ) const

Returns the metric information for the given paint device metric .

另请参阅 PaintDeviceMetric .

[pure virtual] QPaintEngine *QPaintDevice:: paintEngine () const

Returns a pointer to the paint engine used for drawing on the device.

bool QPaintDevice:: paintingActive () const

返回 true if the device is currently being painted on, i.e. someone has called QPainter::begin () but not yet called QPainter::end () for this device; otherwise returns false .

另请参阅 QPainter::isActive ().

int QPaintDevice:: physicalDpiX () const

Returns the horizontal resolution of the device in dots per inch. For example, when printing, this resolution refers to the physical printer's resolution. The logical DPI on the other hand, refers to the resolution used by the actual paint engine.

Note that if the physicalDpiX() doesn't equal the logicalDpiX (), the corresponding QPaintEngine must handle the resolution mapping.

另请参阅 physicalDpiY () 和 logicalDpiX ().

int QPaintDevice:: physicalDpiY () const

Returns the horizontal resolution of the device in dots per inch. For example, when printing, this resolution refers to the physical printer's resolution. The logical DPI on the other hand, refers to the resolution used by the actual paint engine.

Note that if the physicalDpiY() doesn't equal the logicalDpiY (), the corresponding QPaintEngine must handle the resolution mapping.

另请参阅 physicalDpiX () 和 logicalDpiY ().

int QPaintDevice:: width () const

Returns the width of the paint device in default coordinate system units (e.g. pixels for QPixmap and QWidget ).

另请参阅 widthMM ().

int QPaintDevice:: widthMM () const

Returns the width of the paint device in millimeters. Due to platform limitations it may not be possible to use this function to determine the actual physical size of a widget on the screen.

另请参阅 width ().