QPaintDevice 类

QPaintDevice 类是可描绘对象的基类,采用 QPainter . 更多...

Header: #include <QPaintDevice>
CMake: find_package(Qt6 COMPONENTS Gui REQUIRED)
target_link_libraries(mytarget PRIVATE Qt6::Gui)
qmake: QT += gui
继承者:

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

公共类型

enum PaintDeviceMetric { PdmWidth, PdmHeight, PdmWidthMM, PdmHeightMM, PdmNumColors, …, PdmDevicePixelRatioScaled }

公共函数

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

详细描述

描绘设备是 2D 空间的抽象,可以在其上绘制使用 QPainter 。它的默认坐标系统原点位于左上角位置。X 向右递增,Y 向下递增。单位是 1 像素。

目前 QPaintDevice 绘制能力的实现是通过 QWidget , QImage , QPixmap , QPicture ,和 QPrinter 子类。

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.

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 () 和 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

描述描绘设备的各种指标。

常量 描述
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 描绘设备的宽度,以毫米为单位。另请参阅 widthMM ().
QPaintDevice::PdmHeightMM 4 描绘设备的高度,以毫米为单位。另请参阅 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 设备的水平分辨率 (以 DPI 每英寸点数为单位)。另请参阅 logicalDpiX ().
QPaintDevice::PdmDpiY 8 设备的垂直分辨率 (以 DPI 每英寸点数为单位)。另请参阅 logicalDpiY ().
QPaintDevice::PdmPhysicalDpiX 9 设备的水平分辨率 (以 DPI 每英寸点数为单位)。另请参阅 physicalDpiX ().
QPaintDevice::PdmPhysicalDpiY 10 设备的垂直分辨率 (以 DPI 每英寸点数为单位)。另请参阅 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 () 和 devicePixelRatio ().

成员函数文档编制

[protected] QPaintDevice:: QPaintDevice ()

构造描绘装置。此构造函数只可以从 QPaintDevice 子类援引。

[virtual] QPaintDevice:: ~QPaintDevice ()

销毁描绘设备并释放窗口系统资源。

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

返回描绘设备的位深度 (位平面的数量)。

qreal QPaintDevice:: devicePixelRatio () const

返回设备的设备像素比率。

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

[since 5.6] qreal QPaintDevice:: devicePixelRatioF () const

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

该函数在 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 ().

注意:若 logicalDpiX() 不等于 physicalDpiX (),相应 QPaintEngine 必须处理分辨率映射。

另请参阅 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 ().

注意:若 logicalDpiY() 不等于 physicalDpiY (),相应 QPaintEngine 必须处理分辨率映射。

另请参阅 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

返回用于在设备上绘制的描绘引擎指针。

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.

注意:若 physicalDpiX() 不等于 logicalDpiX (),相应 QPaintEngine 必须处理分辨率映射。

另请参阅 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.

注意:若 physicalDpiY() 不等于 logicalDpiY (),相应 QPaintEngine 必须处理分辨率映射。

另请参阅 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 ().