内容表

上一话题

QPagedPaintDevice

下一话题

QPaintDeviceWindow

QPaintDevice

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

Inheritance diagram of PySide2.QtGui.QPaintDevice

继承者: QBitmap , QImage , QPagedPaintDevice , QPicture , QPixmap , QGLFramebufferObject , QGLPixelBuffer , QPrinter , QSvgGenerator

详细描述

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

The drawing capabilities of QPaintDevice are currently implemented by the QWidget , QImage , QPixmap , QGLPixelBuffer , 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.

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

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.

class QPaintDevice

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

PySide2.QtGui.QPaintDevice. PaintDeviceMetric

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

常量

描述

QPaintDevice.PdmWidth

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

QPaintDevice.PdmHeight

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

QPaintDevice.PdmWidthMM

描绘设备的宽度,以毫米为单位。另请参阅 widthMM() .

QPaintDevice.PdmHeightMM

描绘设备的高度,以毫米为单位。另请参阅 heightMM() .

QPaintDevice.PdmNumColors

The number of different colors available for the paint device. See also colorCount() .

QPaintDevice.PdmDepth

The bit depth (number of bit planes) of the paint device. See also depth() .

QPaintDevice.PdmDpiX

设备的水平分辨率 (以 DPI 每英寸点数为单位)。另请参阅 logicalDpiX() .

QPaintDevice.PdmDpiY

设备的垂直分辨率 (以 DPI 每英寸点数为单位)。另请参阅 logicalDpiY() .

QPaintDevice.PdmPhysicalDpiX

设备的水平分辨率 (以 DPI 每英寸点数为单位)。另请参阅 physicalDpiX() .

QPaintDevice.PdmPhysicalDpiY

设备的垂直分辨率 (以 DPI 每英寸点数为单位)。另请参阅 physicalDpiY() .

QPaintDevice.PdmDevicePixelRatio

The device pixel ratio for device. Common values are 1 for normal-dpi displays and 2 for high-dpi “retina” displays.

QPaintDevice.PdmDevicePixelRatioScaled

The scaled device pixel ratio for the device. This is identical to , 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 . This enum value has been introduced in Qt 5.6.

PySide2.QtGui.QPaintDevice. painters
PySide2.QtGui.QPaintDevice. colorCount ( )
返回类型

int

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.

PySide2.QtGui.QPaintDevice. depth ( )
返回类型

int

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

PySide2.QtGui.QPaintDevice. devType ( )
返回类型

int

PySide2.QtGui.QPaintDevice. devicePixelRatio ( )
返回类型

int

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

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

PySide2.QtGui.QPaintDevice. devicePixelRatioF ( )
返回类型

qreal

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

static PySide2.QtGui.QPaintDevice. devicePixelRatioFScale ( )
返回类型

qreal

PySide2.QtGui.QPaintDevice. height ( )
返回类型

int

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

另请参阅

heightMM()

PySide2.QtGui.QPaintDevice. heightMM ( )
返回类型

int

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

PySide2.QtGui.QPaintDevice. initPainter ( painter )
参数

painter QPainter

PySide2.QtGui.QPaintDevice. logicalDpiX ( )
返回类型

int

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 doesn’t equal the physicalDpiX() , the corresponding QPaintEngine 必须处理分辨率映射。

PySide2.QtGui.QPaintDevice. logicalDpiY ( )
返回类型

int

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 doesn’t equal the physicalDpiY() , the corresponding QPaintEngine 必须处理分辨率映射。

PySide2.QtGui.QPaintDevice. metric ( metric )
参数

metric PaintDeviceMetric

返回类型

int

Returns the metric information for the given paint device metric .

另请参阅

PaintDeviceMetric

PySide2.QtGui.QPaintDevice. paintEngine ( )
返回类型

QPaintEngine

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

PySide2.QtGui.QPaintDevice. paintingActive ( )
返回类型

bool

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

另请参阅

isActive()

PySide2.QtGui.QPaintDevice. physicalDpiX ( )
返回类型

int

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 doesn’t equal the logicalDpiX() , the corresponding QPaintEngine 必须处理分辨率映射。

PySide2.QtGui.QPaintDevice. physicalDpiY ( )
返回类型

int

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 doesn’t equal the logicalDpiY() , the corresponding QPaintEngine 必须处理分辨率映射。

PySide2.QtGui.QPaintDevice. redirected ( offset )
参数

offset QPoint

返回类型

QPaintDevice

PySide2.QtGui.QPaintDevice. sharedPainter ( )
返回类型

QPainter

PySide2.QtGui.QPaintDevice. width ( )
返回类型

int

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

另请参阅

widthMM()

PySide2.QtGui.QPaintDevice. widthMM ( )
返回类型

int

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