QPaintDevice 类是可以描绘对象的基类采用 QPainter . 更多...
| 头: |
#include <QPaintDevice>
|
| CMake: |
find_package(Qt6 REQUIRED COMPONENTS Gui)
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, …, PdmDevicePixelRatioF_EncodedB } |
| 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 |
(从 6.8 起)
int
|
encodeMetricF (QPaintDevice::PaintDeviceMetric metric , double value ) |
| QPaintDevice () | |
| virtual int | metric (QPaintDevice::PaintDeviceMetric metric ) const |
描绘设备是 2D 空间的抽象,可以在其上绘制使用 QPainter 。它的默认坐标系原点位于左上角位置。X 向右递增,Y 向下递增。单位是 1 像素。
绘制能力对于 QPaintDevice 是目前实现的通过 QWidget , QImage , QPixmap , QPicture ,和 QPrinter 子类。
要实现支持新后端,必须派生自 QPaintDevice 并重实现虚拟 paintEngine () 函数以告诉 QPainter 应使用哪种描绘引擎在此特定设备中绘制。注意,还必须创建相应描绘引擎才能在设备中绘制,即:派生自 QPaintEngine 并重实现其虚函数。
警告: Qt 要求 QGuiApplication 对象就存在,在可以创建任何描绘设备之前。描绘设备会访问窗口系统资源,且这些资源不会被初始化在创建应用程序对象之前。
QPaintDevice 类提供了返回各种设备指标的几个函数: depth () 函数返回其位深度 (位平面的数量)。 height () 函数以默认坐标系单位返回其高度 (如像素对于 QPixmap and QWidget ) 而 heightMM () 返回设备的高度 (以毫米为单位)。同样, width () 和 widthMM () 函数分别以默认坐标系单位和以毫米为单位返回设备的宽度。另外,受保护的 metric () 函数可以用于检索指标信息通过指定期望的 PaintDeviceMetric 作为自变量。
The logicalDpiX () 和 logicalDpiY () 函数以 DPI (每英寸点数) 为单位返回设备的水平和垂直分辨率。 physicalDpiX () 和 physicalDpiY () 函数还以 DPI (每英寸点数) 为单位返回设备的分辨率,请注意,若逻辑分辨率和物理分辨率不同,相应 QPaintEngine 必须处理映射。最后, colorCount () 函数返回可用于描绘设备的不同颜色的数量。
另请参阅 QPaintEngine , QPainter , 坐标系 ,和 描绘系统 .
描述描绘设备的各种指标。
| 常量 | 值 | 描述 |
|---|---|---|
QPaintDevice::PdmWidth
|
1
|
以默认坐标系单位描绘设备的宽度 (如像素对于 QPixmap and QWidget )。另请参阅 width (). |
QPaintDevice::PdmHeight
|
2
|
以默认坐标系单位描绘设备的高度 (如像素对于 QPixmap and QWidget )。另请参阅 height (). |
QPaintDevice::PdmWidthMM
|
3
|
描绘设备的宽度,以毫米为单位。另请参阅 widthMM (). |
QPaintDevice::PdmHeightMM
|
4
|
描绘设备的高度,以毫米为单位。另请参阅 heightMM (). |
QPaintDevice::PdmNumColors
|
5
|
可用于描绘设备的不同颜色的数量。另请参阅 colorCount (). |
QPaintDevice::PdmDepth
|
6
|
描绘设备的位深度 (位平面的数量)。另请参阅 depth (). |
QPaintDevice::PdmDpiX
|
7
|
设备的水平分辨率 (以 DPI 每英寸点数为单位)。另请参阅 logicalDpiX (). |
QPaintDevice::PdmDpiY
|
8
|
设备的垂直分辨率 (以 DPI 每英寸点数为单位)。另请参阅 logicalDpiY (). |
QPaintDevice::PdmPhysicalDpiX
|
9
|
设备的水平分辨率 (以 DPI 每英寸点数为单位)。另请参阅 physicalDpiX (). |
QPaintDevice::PdmPhysicalDpiY
|
10
|
设备的垂直分辨率 (以 DPI 每英寸点数为单位)。另请参阅 physicalDpiY (). |
QPaintDevice::PdmDevicePixelRatio
|
11
|
设备的设备像素比率。常见值 1 用于正常 DPI (每英寸点数) 显示器,2 用于高 DPI 视网膜显示器。 |
QPaintDevice::PdmDevicePixelRatioScaled
|
12
|
设备的比例缩放设备像素比率。这等同于 PdmDevicePixelRatio,除了值是按常量因子比例缩放以支持具有小数比例缩放因子的描绘设备。所用的常量比例缩放因子是 devicePixelRatioFScale()。该枚举值在 Qt 5.6 引入。 |
QPaintDevice::PdmDevicePixelRatioF_EncodedA (since Qt 6.8)
|
13
|
This enum item, together with the corresponding
B
item, are used together for the device pixel ratio of the device, as an encoded
double
floating point value. A
QPaintDevice
subclass that supports
fractional
DPR values should implement support for these two enum items in its override of the
metric
() function. The return value is expected to be the result of the
encodeMetricF
() 函数。
|
QPaintDevice::PdmDevicePixelRatioF_EncodedB (since Qt 6.8)
|
14
|
See PdmDevicePixelRatioF_EncodedA. |
另请参阅 metric () 和 devicePixelRatio ().
[noexcept protected]
QPaintDevice::
QPaintDevice
()
构造描绘装置。此构造函数只可以从 QPaintDevice 子类援引。
[virtual noexcept]
QPaintDevice::
~QPaintDevice
()
销毁描绘设备并释放窗口系统资源。
返回可用于描绘设备的不同颜色数。若要表示的可用颜色数大于 int 数据类型,则返回 INT_MAX 取而代之。
返回描绘设备的位深度 (位平面的数量)。
返回用于设备的设备像素比率。
常见值为 1 对于普通 DPI (每英寸点数) 显示,和为 2 对于高 DPI 视网膜显示。
以浮点数形式返回设备的设备像素比率。
[static, since 6.8]
int
QPaintDevice::
encodeMetricF
(
QPaintDevice::PaintDeviceMetric
metric
,
double
value
)
返回 value encoded for the metric metric 。子类化实现 metric () 应使用此函数来编码
| 常量 | 描述 |
|---|---|
as
|
an integer return value when the query metric specifies an encoded floating-point value. |
该函数在 Qt 6.8 引入。
返回描绘设备的高度,以默认坐标系单位为单位 (如:像素对于 QPixmap and QWidget ).
另请参阅 heightMM ().
返回描绘设备的高度,以毫米为单位。由于平台局限性,可能无法使用此函数来确定屏幕中 Widget 的实际物理大小。
另请参阅 height ().
返回设备的水平分辨率以 DPI (每英寸点数) 为单位,用于计算字体大小。对于 X11,这通常如同计算从 widthMM ().
注意:若 logicalDpiX() 不等于 physicalDpiX (),相应 QPaintEngine 必须处理分辨率映射。
另请参阅 logicalDpiY () 和 physicalDpiX ().
返回设备的垂直分辨率以 DPI (每英寸点数) 为单位,用于计算字体大小。对于 X11,这通常如同计算从 heightMM ().
注意:若 logicalDpiY() 不等于 physicalDpiY (),相应 QPaintEngine 必须处理分辨率映射。
另请参阅 logicalDpiX () 和 physicalDpiY ().
[virtual protected]
int
QPaintDevice::
metric
(
QPaintDevice::PaintDeviceMetric
metric
) const
返回规格信息为给定描绘设备 metric .
另请参阅 PaintDeviceMetric .
[pure virtual]
QPaintEngine
*QPaintDevice::
paintEngine
() const
返回用于在设备上绘制的描绘引擎指针。
返回
true
若设备目前正在其上描绘,即某人有调用
QPainter::begin
() 但尚未调用
QPainter::end
() 对于此设备;否则返回
false
.
另请参阅 QPainter::isActive ().
返回设备的水平分辨率,以 DPI (每英寸点数) 为单位。例如,当打印时,此分辨率是指物理打印机的分辨率。另一方面,逻辑 DPI 是指实际描绘引擎使用的分辨率。
注意:若 physicalDpiX() 不等于 logicalDpiX (),相应 QPaintEngine 必须处理分辨率映射。
另请参阅 physicalDpiY () 和 logicalDpiX ().
返回设备的水平分辨率,以 DPI (每英寸点数) 为单位。例如,当打印时,此分辨率是指物理打印机的分辨率。另一方面,逻辑 DPI 是指实际描绘引擎使用的分辨率。
注意:若 physicalDpiY() 不等于 logicalDpiY (),相应 QPaintEngine 必须处理分辨率映射。
另请参阅 physicalDpiX () 和 logicalDpiY ().
返回描绘设备的宽度,以默认坐标系单位为单位 (如:像素对于 QPixmap and QWidget ).
另请参阅 widthMM ().
返回描绘设备的宽度,以毫米为单位。由于平台局限性,可能无法使用此函数来确定屏幕中 Widget 的实际物理大小。
另请参阅 width ().