QPaintDevice Class
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 |
- 所有成员的列表,包括继承成员
- QPaintDevice 属于绘画类。
公共类型
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 |
静态公共成员
(since 6.8) int | encodeMetricF(QPaintDevice::PaintDeviceMetric metric, double value) |
保护函数
QPaintDevice() | |
virtual int | metric(QPaintDevice::PaintDeviceMetric metric) const |
详细说明
绘画设备是二维空间的一个抽象概念,可以使用QPainter 在其上绘画。其默认坐标系的原点位于左上方。X 向右增加,Y 向下增加。单位为一个像素。
QPaintDevice 的绘图功能目前由QWidget,QImage,QPixmap,QPicture 和QPrinter 子类实现。
要实现对新后端的支持,您必须派生自 QPaintDevice 并重新实现虚拟paintEngine() 函数,以告诉QPainter 在此特定设备上应使用哪个绘图引擎。请注意,您还必须创建一个相应的绘画引擎才能在设备上绘画,即派生自QPaintEngine 并重新实现其虚拟函数。
警告: Qt 要求在创建任何绘画设备之前,必须存在QGuiApplication 对象。绘画设备会访问窗口系统资源,而这些资源在创建应用程序对象之前不会被初始化。
QPaintDevice 类提供了几个返回各种设备指标的函数:depth() 函数返回其位深度(位平面数)。height() 函数以默认坐标系单位(如QPixmap 和QWidget 的像素)返回设备高度,而heightMM() 函数则以毫米为单位返回设备高度。同样,width() 和widthMM() 函数分别以默认坐标系单位和毫米为单位返回设备的宽度。另外,也可以使用受保护的metric() 函数,通过指定所需的PaintDeviceMetric 作为参数来获取公制信息。
logicalDpiX() 和logicalDpiY() 函数以点/英寸为单位返回设备的水平和垂直分辨率。physicalDpiX() 和physicalDpiY() 函数也以每英寸点为单位返回设备的分辨率,但要注意,如果逻辑分辨率和物理分辨率不同,则相应的QPaintEngine 必须处理映射。最后,colorCount() 函数会返回油漆设备可用的不同颜色的数量。
另请参阅 QPaintEngine,QPainter,坐标系和喷涂系统。
成员类型文档
enum QPaintDevice::PaintDeviceMetric
描述喷涂设备的各种指标。
常数 | 值 | 描述 |
---|---|---|
QPaintDevice::PdmWidth | 1 | 喷涂设备的宽度,以默认坐标系单位表示(例如QPixmap 和QWidget 的像素)。另请参阅width()。 |
QPaintDevice::PdmHeight | 2 | 喷涂设备的高度,以默认坐标系单位表示(例如QPixmap 和QWidget 的像素)。另请参阅height()。 |
QPaintDevice::PdmWidthMM | 3 | 喷涂设备的宽度(以毫米为单位)。另请参阅widthMM()。 |
QPaintDevice::PdmHeightMM | 4 | 喷涂设备的高度(以毫米为单位)。另请参见heightMM()。 |
QPaintDevice::PdmNumColors | 5 | 喷涂装置可用的不同颜色的数量。另请参阅colorCount()。 |
QPaintDevice::PdmDepth | 6 | 喷涂设备的位深度(位平面数量)。另请参见depth()。 |
QPaintDevice::PdmDpiX | 7 | 设备的水平分辨率(点/英寸)。另请参阅logicalDpiX()。 |
QPaintDevice::PdmDpiY | 8 | 设备的垂直分辨率(单位:点/英寸)。另请参阅logicalDpiY()。 |
QPaintDevice::PdmPhysicalDpiX | 9 | 设备的水平分辨率(单位:点/英寸)。另请参阅physicalDpiX()。 |
QPaintDevice::PdmPhysicalDpiY | 10 | 设备的垂直分辨率(单位:点/英寸)。另请参阅physicalDpiY()。 |
QPaintDevice::PdmDevicePixelRatio | 11 | 设备的设备像素比。普通分辨率显示器的常用值为 1,高分辨率 "视网膜 "显示器的常用值为 2。 |
QPaintDevice::PdmDevicePixelRatioScaled | 12 | 设备的缩放设备像素比。该值与 PdmDevicePixelRatio 相同,不同之处在于该值按一个常数因子缩放,以支持具有分数比例因子的喷涂设备。使用的常量缩放因子是 devicePixelRatioFScale()。Qt 5.6 引入了该枚举值。 |
QPaintDevice::PdmDevicePixelRatioF_EncodedA (since Qt 6.8) | 13 | 该枚举项与相应的B 项一起用于设备的设备像素比,作为编码后的double 浮点数值。支持分数DPR 值的QPaintDevice 子类应在其重载的metric() 函数中实现对这两个枚举项的支持。返回值预计是encodeMetricF() 函数的结果。 |
QPaintDevice::PdmDevicePixelRatioF_EncodedB (since Qt 6.8) | 14 | 请参见 PdmDevicePixelRatioF_EncodedA。 |
另请参阅 metric() 和devicePixelRatio()。
成员函数文档
[noexcept protected]
QPaintDevice::QPaintDevice()
构造一个油漆设备。该构造函数只能在 QPaintDevice 的子类中调用。
[virtual noexcept]
QPaintDevice::~QPaintDevice()
销毁油漆设备并释放窗口系统资源。
int QPaintDevice::colorCount() const
返回油漆设备可用的不同颜色的数量。如果可用颜色的数量太多,无法用 int 数据类型表示,则将返回 INT_MAX。
int QPaintDevice::depth() const
返回喷涂设备的位深度(位平面数)。
qreal QPaintDevice::devicePixelRatio() const
返回设备的设备像素比。
对于普通分辨率的显示器,常用值为 1;对于高像素分辨率的 "视网膜 "显示器,常用值为 2。
qreal QPaintDevice::devicePixelRatioF() const
以浮点数形式返回设备的设备像素比。
[static, since 6.8]
int QPaintDevice::encodeMetricF(QPaintDevice::PaintDeviceMetric metric, double value)
返回为公制metric 编码的value 。实现metric() 的子类应使用该函数来编码
常量 | 说明 |
---|---|
as | 当查询度量指定了一个已编码的浮点数值时,该函数将返回一个整数值。 |
此函数在 Qt 6.8 中引入。
int QPaintDevice::height() const
以默认坐标系单位(如QPixmap 和QWidget 的像素)返回喷涂设备的高度。
另请参阅 heightMM()。
int QPaintDevice::heightMM() const
以毫米为单位返回喷涂设备的高度。由于平台限制,可能无法使用此函数确定屏幕上部件的实际物理尺寸。
另请参阅 height()。
int QPaintDevice::logicalDpiX() const
返回设备的水平分辨率(单位:点/英寸),用于计算字体大小。对于 X11,这通常与widthMM() 计算出的结果相同。
请注意,如果 logicalDpiX() 不等于physicalDpiX(),则相应的QPaintEngine 必须处理分辨率映射。
另请参阅 logicalDpiY() 和physicalDpiX()。
int QPaintDevice::logicalDpiY() const
返回设备的垂直分辨率(单位:点/英寸),用于计算字体大小。对于 X11,这通常与heightMM() 计算出的分辨率相同。
请注意,如果 logicalDpiY() 不等于physicalDpiY(),则相应的QPaintEngine 必须处理分辨率映射。
另请参阅 logicalDpiX() 和physicalDpiY()。
[virtual protected]
int QPaintDevice::metric(QPaintDevice::PaintDeviceMetric metric) const
返回给定喷涂设备的度量信息metric 。
另请参见 PaintDeviceMetric 。
[pure virtual]
QPaintEngine *QPaintDevice::paintEngine() const
返回用于在设备上绘图的绘图引擎指针。
bool QPaintDevice::paintingActive() const
如果当前正在绘制设备,即有人已调用QPainter::begin() 但尚未调用QPainter::end() ,则返回true
;否则返回false
。
另请参见 QPainter::isActive()。
int QPaintDevice::physicalDpiX() const
返回设备的水平分辨率(单位:点/英寸)。例如,在打印时,该分辨率指的是物理打印机的分辨率。而逻辑 DPI 指的是实际绘画引擎使用的分辨率。
请注意,如果物理 DpiX() 不等于logicalDpiX() ,则相应的QPaintEngine 必须处理分辨率映射。
另请参阅 physicalDpiY() 和logicalDpiX()。
int QPaintDevice::physicalDpiY() const
返回设备的水平分辨率(单位:点/英寸)。例如,在打印时,该分辨率指的是物理打印机的分辨率。而逻辑 DPI 指的是实际绘画引擎使用的分辨率。
请注意,如果物理 DpiY() 不等于logicalDpiY() ,则相应的QPaintEngine 必须处理分辨率映射。
另请参阅 physicalDpiX() 和logicalDpiY()。
int QPaintDevice::width() const
以默认坐标系单位(如QPixmap 和QWidget 的像素)返回喷涂设备的宽度。
另请参阅 widthMM()。
int QPaintDevice::widthMM() const
以毫米为单位返回绘画设备的宽度。由于平台限制,可能无法使用此函数确定屏幕上部件的实际物理尺寸。
另请参阅 width()。
© 2025 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.