QPainter

QPainter class performs low-level painting on widgets and other paint devices. 更多

Inheritance diagram of PySide2.QtGui.QPainter

继承者: QStylePainter

概要

函数

静态函数

详细描述

QPainter provides highly optimized functions to do most of the drawing GUI programs require. It can draw everything from simple lines to complex shapes like pies and chords. It can also draw aligned text and pixmaps. Normally, it draws in a “natural” coordinate system, but it can also do view and world transformation. QPainter can operate on any object that inherits the QPaintDevice 类。

The common use of QPainter is inside a widget’s paint event: Construct and customize (e.g. set the pen or the brush) the painter. Then draw. Remember to destroy the QPainter object after drawing. For example:

def paintEvent(self, paintEvent):
    painter = QPainter(self)
    painter.setPen(Qt.blue)
    painter.setFont(QFont("Arial", 30))
    painter.drawText(rect(), Qt.AlignCenter, "Qt")
											

The core functionality of QPainter is drawing, but the class also provide several functions that allows you to customize QPainter ‘s settings and its rendering quality, and others that enable clipping. In addition you can control how different shapes are merged together by specifying the painter’s composition mode.

isActive() function indicates whether the painter is active. A painter is activated by the begin() function and the constructor that takes a QPaintDevice 自变量。 end() function, and the destructor, deactivates it.

连同 QPaintDevice and QPaintEngine classes, QPainter form the basis for Qt’s paint system. QPainter is the class used to perform drawing operations. QPaintDevice represents a device that can be painted on using a QPainter . QPaintEngine 提供用于在不同类型设备上描绘的描绘器接口。若描绘器活动, device() returns the paint device on which the painter paints, and paintEngine() returns the paint engine that the painter is currently operating on. For more information, see the 描绘系统 .

有时,可能期望其它人去描绘在不寻常 QPaintDevice . QPainter supports a static function to do this, setRedirected() .

警告

When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent().

设置

There are several settings that you can customize to make QPainter draw according to your preferences:

注意:其中一些设置会镜像某些绘制设备设置,如 font() begin() function (or equivalently the QPainter constructor) copies these attributes from the paint device.

You can at any time save the QPainter ‘s state by calling the save() function which saves all the available settings on an internal stack. The restore() function pops them back.

绘制

QPainter provides functions to draw most primitives: drawPoint() , drawPoints() , drawLine() , drawRect() , drawRoundedRect() , drawEllipse() , drawArc() , drawPie() , drawChord() , drawPolyline() , drawPolygon() , drawConvexPolygon() and drawCubicBezier(). The two convenience functions, drawRects() and drawLines() , draw the given number of rectangles or lines in the given array of QRects or QLines 使用当前钢笔和笔刷。

QPainter class also provides the fillRect() function which fills the given QRect ,采用给定 QBrush ,和 eraseRect() function that erases the area inside the given rectangle.

所有这些函数都有整数和浮点版本。

qpainter-basicdrawing1

基本绘制范例

基本绘制 example shows how to display basic graphics primitives in a variety of styles using the QPainter 类。

If you need to draw a complex shape, especially if you need to do so repeatedly, consider creating a QPainterPath and drawing it using drawPath() .

描绘器路径范例

QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused.

Painter Paths example shows how painter paths can be used to build complex shapes for rendering.

qpainter-painterpaths2

QPainter also provides the fillPath() function which fills the given QPainterPath 采用给定 QBrush ,和 strokePath() function that draws the outline of the given path (i.e. strokes the path).

另请参阅 向量变形 example which shows how to use advanced vector techniques to draw text using a QPainterPath 渐变 example which shows the different types of gradients that are available in Qt, and the 路径笔画 example which shows Qt’s built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns.

向量变形

渐变

路径笔画

qpainter-vectordeformation3

qpainter-gradients4

qpainter-pathstroking5

Text drawing is done using drawText() . When you need fine-grained positioning, boundingRect() tells you where a given drawText() command will draw.

绘制像素图和图像

There are functions to draw pixmaps/images, namely drawPixmap() , drawImage() and drawTiledPixmap() . Both drawPixmap() and drawImage() produce the same result, except that drawPixmap() is faster on-screen while drawImage() may be faster on a QPrinter or other devices.

There is a drawPicture() function that draws the contents of an entire QPicture drawPicture() function is the only function that disregards all the painter’s settings as QPicture has its own settings.

绘制高分辨率版本的像素图和图像

High resolution versions of pixmaps have a device pixel ratio value larger than 1 (see QImageReader , devicePixelRatio() ). Should it match the value of the underlying QPaintDevice , it is drawn directly onto the device with no additional transformation applied.

This is for example the case when drawing a QPixmap of 64x64 pixels size with a device pixel ratio of 2 onto a high DPI screen which also has a device pixel ratio of 2. Note that the pixmap is then effectively 32x32 pixels in user space . Code paths in Qt that calculate layout geometry based on the pixmap size will use this size. The net effect of this is that the pixmap is displayed as high DPI pixmap rather than a large pixmap.

渲染品质

To get the optimal rendering result using QPainter , you should use the platform independent QImage as paint device; i.e. using QImage will ensure that the result has an identical pixel representation on any platform.

QPainter class also provides a means of controlling the rendering quality through its RenderHint enum and the support for floating point precision: All the functions for drawing primitives has a floating point version. These are often used in combination with the 抗锯齿 render hint.

qpainter-concentriccircles6

同心圆范例

Concentric Circles example shows the improved rendering quality that can be obtained using floating point precision and anti-aliasing when drawing custom widgets.

The application’s main window displays several widgets which are drawn using the various combinations of precision and anti-aliasing.

RenderHint enum specifies flags to QPainter that may or may not be respected by any given engine. 抗锯齿 indicates that the engine should antialias edges of primitives if possible, TextAntialiasing indicates that the engine should antialias text if possible, and the SmoothPixmapTransform indicates that the engine should use a smooth pixmap transformation algorithm.

renderHints() function returns a flag that specifies the rendering hints that are set for this painter. Use the setRenderHint() function to set or clear the currently set RenderHints .

坐标变换

Normally, the QPainter operates on the device’s own coordinate system (usually pixels), but QPainter has good support for coordinate transformations.

nop

rotate()

scale()

translate()

qpainter-clock7

qpainter-rotation8

qpainter-scale9

qpainter-translation10

The most commonly used transformations are scaling, rotation, translation and shearing. Use the scale() function to scale the coordinate system by a given offset, the rotate() function to rotate it clockwise and translate() to translate it (i.e. adding a given offset to the points). You can also twist the coordinate system around the origin using the shear() function. See the 仿射变换 example for a visualization of a sheared coordinate system.

另请参阅 变换 example which shows how transformations influence the way that QPainter renders graphics primitives. In particular it shows how the order of transformations affects the result.

仿射变换范例

仿射变换 example shows Qt’s ability to perform affine transformations on painting operations. The demo also allows the user to experiment with the transformation operations and see the results immediately.

qpainter-affinetransformations11

All the tranformation operations operate on the transformation worldTransform() . A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see the 坐标系统 and QTransform 文档编制。

setWorldTransform() function can replace or add to the currently set worldTransform() resetTransform() function resets any transformations that were made using translate() , scale() , shear() , rotate() , setWorldTransform() , setViewport() and setWindow() functions. The deviceTransform() returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device. The latter function is only needed when using platform painting commands on the platform dependent handle, and the platform does not do transformations nativly.

When drawing with QPainter , we specify points using logical coordinates which then are converted into the physical coordinates of the paint device. The mapping of the logical coordinates to the physical coordinates are handled by QPainter ‘s combinedTransform() , a combination of viewport() and window() and worldTransform() viewport() represents the physical coordinates specifying an arbitrary rectangle, the window() describes the same rectangle in logical coordinates, and the worldTransform() is identical with the transformation matrix.

另请参阅 坐标系统

Clipping

QPainter can clip any drawing operation to a rectangle, a region, or a vector path. The current clip is available using the functions clipRegion() and clipPath() . Whether paths or regions are preferred (faster) depends on the underlying paintEngine() . For example, the QImage paint engine prefers paths while the X11 paint engine prefers regions. Setting a clip is done in the painters logical coordinates.

After QPainter ‘s clipping, the paint device may also clip. For example, most widgets clip away the pixels used by child widgets, and most printers clip away an area near the edges of the paper. This additional clipping is not reflected by the return value of clipRegion() or hasClipping() .

复合模式

QPainter provides the CompositionMode enum which defines the Porter-Duff rules for digital image compositing; it describes a model for combining the pixels in one image, the source, with the pixels in another image, the destination.

The two most common forms of composition are Source and SourceOver . Source is used to draw opaque objects onto a paint device. In this mode, each pixel in the source replaces the corresponding pixel in the destination. In SourceOver composition mode, the source object is transparent and is drawn on top of the destination.

Note that composition transformation operates pixelwise. For that reason, there is a difference between using the graphic primitive itself and its bounding rectangle: The bounding rect contains pixels with alpha == 0 (i.e the pixels surrounding the primitive). These pixels will overwrite the other image’s pixels, effectively clearing those, while the primitive only overwrites its own area.

qpainter-compositiondemo12

合成模式范例

复合模式 example, available in Qt’s examples directory, allows you to experiment with the various composition modes and see the results immediately.

局限性

If you are using coordinates with Qt’s raster-based paint engine, it is important to note that, while coordinates greater than +/- 2 15 can be used, any painting performed with coordinates outside this range is not guaranteed to be shown; the drawing may be clipped. This is due to the use of short int in the implementation.

The outlines generated by Qt’s stroker are only an approximation when dealing with curved shapes. It is in most cases impossible to represent the outline of a bezier curve segment using another bezier curve segment, and so Qt approximates the curve outlines by using several smaller curves. For performance reasons there is a limit to how many curves Qt uses for these outlines, and thus when using large pen widths or scales the outline error increases. To generate outlines with smaller errors it is possible to use the QPainterPathStroker class, which has the setCurveThreshold member function which let’s the user specify the error tolerance. Another workaround is to convert the paths to polygons first and then draw the polygons instead.

性能

QPainter is a rich framework that allows developers to do a great variety of graphical operations, such as gradients, composition modes and vector graphics. And QPainter can do this across a variety of different hardware and software stacks. Naturally the underlying combination of hardware and software has some implications for performance, and ensuring that every single operation is fast in combination with all the various combinations of composition modes, brushes, clipping, transformation, etc, is close to an impossible task because of the number of permutations. As a compromise we have selected a subset of the QPainter API and backends, where performance is guaranteed to be as good as we can sensibly get it for the given combination of hardware and software.

The backends we focus on as high-performance engines are:

  • Raster - This backend implements all rendering in pure software and is always used to render into QImages. For optimal performance only use the format types Format_ARGB32_Premultiplied , Format_RGB32 or Format_RGB16 . Any other format, including Format_ARGB32 , has significantly worse performance. This engine is used by default for QWidget and QPixmap .

  • OpenGL 2.0 (ES) - This backend is the primary backend for hardware accelerated graphics. It can be run on desktop machines and embedded devices supporting the OpenGL 2.0 or OpenGL/ES 2.0 specification. This includes most graphics chips produced in the last couple of years. The engine can be enabled by using QPainter onto a QOpenGLWidget .

These operations are:

  • Simple transformations, meaning translation and scaling, pluss 0, 90, 180, 270 degree rotations.

  • drawPixmap() in combination with simple transformations and opacity with non-smooth transformation mode ( QPainter::SmoothPixmapTransform not enabled as a render hint).

  • Rectangle fills with solid color, two-color linear gradients and simple transforms.

  • Rectangular clipping with simple transformations and intersect clip.

  • 复合模式 QPainter::CompositionMode_Source and CompositionMode_SourceOver .

  • Rounded rectangle filling using solid color and two-color linear gradients fills.

  • 3x3 patched pixmaps, via .

This list gives an indication of which features to safely use in an application where performance is critical. For certain setups, other operations may be fast too, but before making extensive use of them, it is recommended to benchmark and verify them on the system where the software will run in the end. There are also cases where expensive operations are ok to use, for instance when the result is cached in a QPixmap .

另请参阅

QPaintDevice QPaintEngine Qt SVG 基本绘制范例 绘制 Utility 函数

class QPainter

QPainter(arg__1)

param arg__1

QPaintDevice

构造描绘器。

另请参阅

begin() end()

Constructs a painter that begins painting the paint device immediately.

This constructor is convenient for short-lived painters, e.g. in a paintEvent() and should be used only once. The constructor calls begin() for you and the QPainter destructor automatically calls end() .

Here’s an example using begin() and end() :

def paintEvent(self, paintEvent):
    p = QPainter()
    p.begin(self)
    p.drawLine(...)         # drawing code
    p.end()
												

The same example using this constructor:

self paintEvent(self, paintEvent):
    p = QPainter(self)
    p.drawLine(...)         # drawing code
												

Since the constructor cannot provide feedback when the initialization of the painter failed you should rather use begin() and end() to paint on external devices, e.g. printers.

另请参阅

begin() end()

PySide2.QtGui.QPainter. RenderHint

Renderhints are used to specify flags to QPainter that may or may not be respected by any given engine.

常量

描述

QPainter.Antialiasing

Indicates that the engine should antialias edges of primitives if possible.

QPainter.TextAntialiasing

Indicates that the engine should antialias text if possible. To forcibly disable antialiasing for text, do not use this hint. Instead, set NoAntialias on your font’s style strategy.

QPainter.SmoothPixmapTransform

Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.

QPainter.HighQualityAntialiasing

This value is obsolete and will be ignored, use the Antialiasing render hint instead.

QPainter.NonCosmeticDefaultPen

This value is obsolete, the default for QPen is now non-cosmetic.

QPainter.Qt4CompatiblePainting

Compatibility hint telling the engine to use the same X11 based fill rules as in Qt 4, where aliased rendering is offset by slightly less than half a pixel. Also will treat default constructed pens as cosmetic. Potentially useful when porting a Qt 4 application to Qt 5.

QPainter.LosslessImageRendering

Use a lossless image rendering, whenever possible. Currently, this hint is only used when QPainter is employed to output a PDF file through QPrinter or QPdfWriter ,其中 drawImage() / drawPixmap() calls will encode images using a lossless compression algorithm instead of lossy JPEG compression. This value was added in Qt 5.13.

PySide2.QtGui.QPainter. PixmapFragmentHint

常量

描述

QPainter.OpaqueHint

Indicates that the pixmap fragments to be drawn are opaque. Opaque fragments are potentially faster to draw.

另请参阅

drawPixmapFragments() PixmapFragment

New in version 4.7.

PySide2.QtGui.QPainter. CompositionMode

Defines the modes supported for digital image compositing. Composition modes are used to specify how the pixels in one image, the source, are merged with the pixel in another image, the destination.

Please note that the bitwise raster operation modes, denoted with a RasterOp prefix, are only natively supported in the X11 and raster paint engines. This means that the only way to utilize these modes on the Mac is via a QImage . The RasterOp denoted blend modes are not supported for pens and brushes with alpha components. Also, turning on the 抗锯齿 render hint will effectively disable the RasterOp modes.

../../_images/qpainter-compositionmode1.png ../../_images/qpainter-compositionmode2.png

The most common type is SourceOver (often referred to as just alpha blending) where the source pixel is blended on top of the destination pixel in such a way that the alpha component of the source defines the translucency of the pixel.

Several composition modes require an alpha channel in the source or target images to have an effect. For optimal performance the image format Format_ARGB32_Premultiplied is preferred.

When a composition mode is set it applies to all painting operator, pens, brushes, gradients and pixmap/image drawing.

常量

描述

QPainter.CompositionMode_SourceOver

This is the default mode. The alpha of the source is used to blend the pixel on top of the destination.

QPainter.CompositionMode_DestinationOver

The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of .

QPainter.CompositionMode_Clear

The pixels in the destination are cleared (set to fully transparent) independent of the source.

QPainter.CompositionMode_Source

The output is the source pixel. (This means a basic copy operation and is identical to SourceOver when the source pixel is opaque).

QPainter.CompositionMode_Destination

The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of .

QPainter.CompositionMode_SourceIn

The output is the source, where the alpha is reduced by that of the destination.

QPainter.CompositionMode_DestinationIn

The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of .

QPainter.CompositionMode_SourceOut

The output is the source, where the alpha is reduced by the inverse of destination.

QPainter.CompositionMode_DestinationOut

The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of .

QPainter.CompositionMode_SourceAtop

The source pixel is blended on top of the destination, with the alpha of the source pixel reduced by the alpha of the destination pixel.

QPainter.CompositionMode_DestinationAtop

The destination pixel is blended on top of the source, with the alpha of the destination pixel is reduced by the alpha of the destination pixel. This mode is the inverse of .

QPainter.CompositionMode_Xor

The source, whose alpha is reduced with the inverse of the destination alpha, is merged with the destination, whose alpha is reduced by the inverse of the source alpha. is not the same as the bitwise Xor.

QPainter.CompositionMode_Plus

Both the alpha and color of the source and destination pixels are added together.

QPainter.CompositionMode_Multiply

The output is the source color multiplied by the destination. Multiplying a color with white leaves the color unchanged, while multiplying a color with black produces black.

QPainter.CompositionMode_Screen

The source and destination colors are inverted and then multiplied. Screening a color with white produces white, whereas screening a color with black leaves the color unchanged.

QPainter.CompositionMode_Overlay

Multiplies or screens the colors depending on the destination color. The destination color is mixed with the source color to reflect the lightness or darkness of the destination.

QPainter.CompositionMode_Darken

The darker of the source and destination colors is selected.

QPainter.CompositionMode_Lighten

The lighter of the source and destination colors is selected.

QPainter.CompositionMode_ColorDodge

The destination color is brightened to reflect the source color. A black source color leaves the destination color unchanged.

QPainter.CompositionMode_ColorBurn

The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged.

QPainter.CompositionMode_HardLight

Multiplies or screens the colors depending on the source color. A light source color will lighten the destination color, whereas a dark source color will darken the destination color.

QPainter.CompositionMode_SoftLight

Darkens or lightens the colors depending on the source color. Similar to .

QPainter.CompositionMode_Difference

Subtracts the darker of the colors from the lighter. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.

QPainter.CompositionMode_Exclusion

Similar to , but with a lower contrast. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.

QPainter.RasterOp_SourceOrDestination

Does a bitwise OR operation on the source and destination pixels (src OR dst).

QPainter.RasterOp_SourceAndDestination

Does a bitwise AND operation on the source and destination pixels (src AND dst).

QPainter.RasterOp_SourceXorDestination

Does a bitwise XOR operation on the source and destination pixels (src XOR dst).

QPainter.RasterOp_NotSourceAndNotDestination

Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)).

QPainter.RasterOp_NotSourceOrNotDestination

Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)).

QPainter.RasterOp_NotSourceXorDestination

Does a bitwise operation where the source pixels are inverted and then XOR’ed with the destination ((NOT src) XOR dst).

QPainter.RasterOp_NotSource

Does a bitwise operation where the source pixels are inverted (NOT src).

QPainter.RasterOp_NotSourceAndDestination

Does a bitwise operation where the source is inverted and then AND’ed with the destination ((NOT src) AND dst).

QPainter.RasterOp_SourceAndNotDestination

Does a bitwise operation where the source is AND’ed with the inverted destination pixels (src AND (NOT dst)).

QPainter.RasterOp_NotSourceOrDestination

Does a bitwise operation where the source is inverted and then OR’ed with the destination ((NOT src) OR dst).

QPainter.RasterOp_ClearDestination

The pixels in the destination are cleared (set to 0) independent of the source.

QPainter.RasterOp_SetDestination

The pixels in the destination are set (set to 1) independent of the source.

QPainter.RasterOp_NotDestination

Does a bitwise operation where the destination pixels are inverted (NOT dst).

QPainter.RasterOp_SourceOrNotDestination

Does a bitwise operation where the source is OR’ed with the inverted destination pixels (src OR (NOT dst)).

PySide2.QtGui.QPainter. background ( )
返回类型

QBrush

返回当前背景笔刷。

另请参阅

setBackground() 设置

PySide2.QtGui.QPainter. backgroundMode ( )
返回类型

BGMode

返回当前背景模式。

另请参阅

setBackgroundMode() 设置

PySide2.QtGui.QPainter. begin ( arg__1 )
参数

arg__1 QPaintDevice

返回类型

bool

Begins painting the paint device 并返回 true 若成功;否则返回 false .

Notice that all painter settings ( setPen() , setBrush() etc.) are reset to default values when is called.

The errors that can occur are serious problems, such as these:

painter.begin(0)  # impossible - paint device cannot be 0
image = QPixmap(0, 0)
painter.begin(&image) # impossible - image.isNull() == true
painter.begin(myWidget)
painter2.begin(myWidget) # impossible - only one painter at a time
												

Note that most of the time, you can use one of the constructors instead of , and that end() is automatically done at destruction.

警告

A paint device can only be painted by one painter at a time.

警告

Painting on a QImage with the format Format_Indexed8 不被支持。

另请参阅

end() QPainter()

PySide2.QtGui.QPainter. beginNativePainting ( )

Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying graphics context. Must be followed by a call to endNativePainting() .

Note that only the states the underlying paint engine changes will be reset to their respective default states. The states we reset may change from release to release. The following states are currently reset in the OpenGL 2 engine:

  • blending is disabled

  • the depth, stencil and scissor tests are disabled

  • the active texture unit is reset to 0

  • the depth mask, depth function and the clear depth are reset to their default values

  • the stencil mask, stencil operation and stencil function are reset to their default values

  • the current color is reset to solid white

If, for example, the OpenGL polygon mode is changed by the user inside a beginNativePaint()/ endNativePainting() block, it will not be reset to the default state by endNativePainting() . Here is an example that shows intermixing of painter commands and raw OpenGL commands:

painter = QPainter(self)
painter.fillRect(0, 0, 128, 128, Qt.green)
painter.beginNativePainting()
glEnable(GL_SCISSOR_TEST)
glScissor(0, 0, 64, 64)
glClearColor(1, 0, 0, 1)
glClear(GL_COLOR_BUFFER_BIT)
glDisable(GL_SCISSOR_TEST)
painter.endNativePainting()
												
PySide2.QtGui.QPainter. boundingRect ( rect , flags , text )
参数
  • rect QRect

  • flags int

  • text – unicode

返回类型

QRect

PySide2.QtGui.QPainter. boundingRect ( rect , text [ , o=QTextOption() ] )
参数
返回类型

QRectF

PySide2.QtGui.QPainter. boundingRect ( rect , flags , text )
参数
  • rect QRectF

  • flags int

  • text – unicode

返回类型

QRectF

PySide2.QtGui.QPainter. boundingRect ( x , y , w , h , flags , text )
参数
  • x int

  • y int

  • w int

  • h int

  • flags int

  • text – unicode

返回类型

QRect

这是重载函数。

Returns the bounding rectangle of the given text as it will appear when drawn inside the rectangle beginning at the point ( x , y ) with width w and height h .

PySide2.QtGui.QPainter. brush ( )
返回类型

QBrush

Returns the painter’s current brush.

另请参阅

setBrush() 设置

PySide2.QtGui.QPainter. brushOrigin ( )
返回类型

QPoint

Returns the currently set brush origin.

另请参阅

setBrushOrigin() 设置

PySide2.QtGui.QPainter. clipBoundingRect ( )
返回类型

QRectF

Returns the bounding rectangle of the current clip if there is a clip; otherwise returns an empty rectangle. Note that the clip region is given in logical coordinates.

The bounding rectangle is not guaranteed to be tight.

PySide2.QtGui.QPainter. clipPath ( )
返回类型

QPainterPath

Returns the current clip path in logical coordinates.

警告

QPainter does not store the combined clip explicitly as this is handled by the underlying QPaintEngine , so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.

PySide2.QtGui.QPainter. clipRegion ( )
返回类型

QRegion

Returns the currently set clip region. Note that the clip region is given in logical coordinates.

警告

QPainter does not store the combined clip explicitly as this is handled by the underlying QPaintEngine , so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.

PySide2.QtGui.QPainter. combinedMatrix ( )
返回类型

QMatrix

注意

此函数被弃用。

Returns the transformation matrix combining the current window/viewport and world transformation.

It is advisable to use combinedTransform() instead of this function to preserve the properties of perspective transformations.

PySide2.QtGui.QPainter. combinedTransform ( )
返回类型

QTransform

Returns the transformation matrix combining the current window/viewport and world transformation.

PySide2.QtGui.QPainter. compositionMode ( )
返回类型

CompositionMode

Returns the current composition mode.

另请参阅

CompositionMode setCompositionMode()

PySide2.QtGui.QPainter. device ( )
返回类型

QPaintDevice

Returns the paint device on which this painter is currently painting, or None if the painter is not active.

另请参阅

isActive()

PySide2.QtGui.QPainter. deviceMatrix ( )
返回类型

QMatrix

注意

此函数被弃用。

Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.

注意

It is advisable to use deviceTransform() instead of this function to preserve the properties of perspective transformations.

此函数是 only needed when using platform painting commands on the platform dependent handle ( HANDLE ), and the platform does not do transformations nativly.

PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

PySide2.QtGui.QPainter. deviceTransform ( )
返回类型

QTransform

Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.

此函数是 only needed when using platform painting commands on the platform dependent handle ( HANDLE ), and the platform does not do transformations nativly.

PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

PySide2.QtGui.QPainter. drawArc ( arg__1 , a , alen )
参数
  • arg__1 QRect

  • a int

  • alen int

PySide2.QtGui.QPainter. drawArc ( rect , a , alen )
参数
  • rect QRectF

  • a int

  • alen int

PySide2.QtGui.QPainter. drawArc ( x , y , w , h , a , alen )
参数
  • x int

  • y int

  • w int

  • h int

  • a int

  • alen int

这是重载函数。

Draws the arc defined by the rectangle beginning at ( x , y ) with the specified width and height ,和给定 startAngle and spanAngle .

PySide2.QtGui.QPainter. drawChord ( arg__1 , a , alen )
参数
  • arg__1 QRect

  • a int

  • alen int

PySide2.QtGui.QPainter. drawChord ( rect , a , alen )
参数
  • rect QRectF

  • a int

  • alen int

PySide2.QtGui.QPainter. drawChord ( x , y , w , h , a , alen )
参数
  • x int

  • y int

  • w int

  • h int

  • a int

  • alen int

这是重载函数。

Draws the chord defined by the rectangle beginning at ( x , y ) with the specified width and height ,和给定 startAngle and spanAngle .

PySide2.QtGui.QPainter. drawConvexPolygon ( arg__1 )
参数

arg__1

PySide2.QtGui.QPainter. drawConvexPolygon ( polygon )
参数

polygon QPolygonF

PySide2.QtGui.QPainter. drawConvexPolygon ( polygon )
参数

polygon QPolygon

PySide2.QtGui.QPainter. drawConvexPolygon ( arg__1 )
参数

arg__1

PySide2.QtGui.QPainter. drawEllipse ( center , rx , ry )
参数
  • center QPoint

  • rx int

  • ry int

PySide2.QtGui.QPainter. drawEllipse ( center , rx , ry )
参数
  • center QPointF

  • rx qreal

  • ry qreal

PySide2.QtGui.QPainter. drawEllipse ( r )
参数

r QRect

PySide2.QtGui.QPainter. drawEllipse ( r )
参数

r QRectF

PySide2.QtGui.QPainter. drawEllipse ( x , y , w , h )
参数
  • x int

  • y int

  • w int

  • h int

这是重载函数。

Draws the ellipse defined by the rectangle beginning at ( x , y ) with the given width and height .

PySide2.QtGui.QPainter. drawImage ( targetRect , image , sourceRect [ , flags=Qt.AutoColor ] )
参数
  • targetRect QRect

  • image QImage

  • sourceRect QRect

  • flags ImageConversionFlags

PySide2.QtGui.QPainter. drawImage ( x , y , image [ , sx=0 [ , sy=0 [ , sw=-1 [ , sh=-1 [ , flags=Qt.AutoColor ] ] ] ] ] )
参数
  • x int

  • y int

  • image QImage

  • sx int

  • sy int

  • sw int

  • sh int

  • flags ImageConversionFlags

这是重载函数。

Draws an image at ( x , y ) by copying a part of image into the paint device.

( x , y ) specifies the top-left point in the paint device that is to be drawn onto. ( sx , sy ) specifies the top-left point in image that is to be drawn. The default is (0, 0).

( sw , sh ) specifies the size of the image that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the image.

PySide2.QtGui.QPainter. drawImage ( targetRect , image , sourceRect [ , flags=Qt.AutoColor ] )
参数
  • targetRect QRectF

  • image QImage

  • sourceRect QRectF

  • flags ImageConversionFlags

PySide2.QtGui.QPainter. drawImage ( r , image )
参数
PySide2.QtGui.QPainter. drawImage ( r , image )
参数
PySide2.QtGui.QPainter. drawImage ( p , image , sr [ , flags=Qt.AutoColor ] )
参数
  • p QPointF

  • image QImage

  • sr QRectF

  • flags ImageConversionFlags

PySide2.QtGui.QPainter. drawImage ( p , image )
参数
PySide2.QtGui.QPainter. drawImage ( p , image , sr [ , flags=Qt.AutoColor ] )
参数
  • p QPoint

  • image QImage

  • sr QRect

  • flags ImageConversionFlags

PySide2.QtGui.QPainter. drawImage ( p , image )
参数
PySide2.QtGui.QPainter. drawLine ( line )
参数

line QLine

PySide2.QtGui.QPainter. drawLine ( line )
参数

line QLineF

PySide2.QtGui.QPainter. drawLine ( p1 , p2 )
参数
  • p1 QPoint

  • p2 QPoint

PySide2.QtGui.QPainter. drawLine ( p1 , p2 )
参数
  • p1 QPointF

  • p2 QPointF

PySide2.QtGui.QPainter. drawLine ( x1 , y1 , x2 , y2 )
参数
  • x1 int

  • y1 int

  • x2 int

  • y2 int

这是重载函数。

Draws a line from ( x1 , y1 ) to ( x2 , y2 ).

PySide2.QtGui.QPainter. drawLines ( lines )
参数

lines

PySide2.QtGui.QPainter. drawLines ( pointPairs )
参数

pointPairs

PySide2.QtGui.QPainter. drawLines ( pointPairs )
参数

pointPairs

PySide2.QtGui.QPainter. drawLines ( lines )
参数

lines

PySide2.QtGui.QPainter. drawPath ( path )
参数

path QPainterPath

Draws the given painter path using the current pen for outline and the current brush for filling.

qpainter-path1

path = QPainterPath()
path.moveTo(20, 80)
path.lineTo(20, 30)
path.cubicTo(80, 0, 50, 50, 80, 80)
painter = QPainter(self)
painter.drawPath(path)
																
PySide2.QtGui.QPainter. drawPicture ( p , picture )
参数
PySide2.QtGui.QPainter. drawPicture ( p , picture )
参数
PySide2.QtGui.QPainter. drawPicture ( x , y , picture )
参数

这是重载函数。

绘制给定 picture at point ( x , y ).

PySide2.QtGui.QPainter. drawPie ( arg__1 , a , alen )
参数
  • arg__1 QRect

  • a int

  • alen int

PySide2.QtGui.QPainter. drawPie ( x , y , w , h , a , alen )
参数
  • x int

  • y int

  • w int

  • h int

  • a int

  • alen int

这是重载函数。

Draws the pie defined by the rectangle beginning at ( x , y ) with the specified width and height ,和给定 startAngle and spanAngle .

PySide2.QtGui.QPainter. drawPie ( rect , a , alen )
参数
  • rect QRectF

  • a int

  • alen int

PySide2.QtGui.QPainter. drawPixmap ( p , pm , sr )
参数
PySide2.QtGui.QPainter. drawPixmap ( x , y , w , h , pm , sx , sy , sw , sh )
参数
  • x int

  • y int

  • w int

  • h int

  • pm QPixmap

  • sx int

  • sy int

  • sw int

  • sh int

这是重载函数。

Draws the rectangular portion with the origin ( sx , sy ), width sw and height sh , of the given pixmap , at the point ( x , y ), with a width of w and a height of h . If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy;

PySide2.QtGui.QPainter. drawPixmap ( x , y , w , h , pm )
参数
  • x int

  • y int

  • w int

  • h int

  • pm QPixmap

这是重载函数。

Draws the pixmap into the rectangle at position ( x , y ) with the given width and height .

PySide2.QtGui.QPainter. drawPixmap ( x , y , pm , sx , sy , sw , sh )
参数
  • x int

  • y int

  • pm QPixmap

  • sx int

  • sy int

  • sw int

  • sh int

这是重载函数。

Draws a pixmap at ( x , y ) by copying a part of the given pixmap into the paint device.

( x , y ) specifies the top-left point in the paint device that is to be drawn onto. ( sx , sy ) specifies the top-left point in pixmap that is to be drawn. The default is (0, 0).

( sw , sh ) specifies the size of the pixmap that is to be drawn. The default, (0, 0) (and negative) means all the way to the bottom-right of the pixmap.

PySide2.QtGui.QPainter. drawPixmap ( x , y , pm )
参数
PySide2.QtGui.QPainter. drawPixmap ( targetRect , pixmap , sourceRect )
参数
  • targetRect QRectF

  • pixmap QPixmap

  • sourceRect QRectF

PySide2.QtGui.QPainter. drawPixmap ( targetRect , pixmap , sourceRect )
参数
  • targetRect QRect

  • pixmap QPixmap

  • sourceRect QRect

PySide2.QtGui.QPainter. drawPixmap ( r , pm )
参数
PySide2.QtGui.QPainter. drawPixmap ( p , pm )
参数
PySide2.QtGui.QPainter. drawPixmap ( p , pm , sr )
参数
PySide2.QtGui.QPainter. drawPixmap ( p , pm )
参数
PySide2.QtGui.QPainter. drawPixmapFragments ( fragments , fragmentCount , pixmap [ , hints=QPainter.PixmapFragmentHints() ] )
参数

This function is used to draw pixmap , or a sub-rectangle of pixmap , at multiple positions with different scale, rotation and opacity. fragments is an array of fragmentCount elements specifying the parameters used to draw each pixmap fragment. The hints parameter can be used to pass in drawing hints.

This function is potentially faster than multiple calls to drawPixmap() , since the backend can optimize state changes.

另请参阅

PixmapFragment PixmapFragmentHint

PySide2.QtGui.QPainter. drawPoint ( p )
参数

p QPoint

PySide2.QtGui.QPainter. drawPoint ( pt )
参数

pt QPointF

PySide2.QtGui.QPainter. drawPoint ( x , y )
参数
  • x int

  • y int

这是重载函数。

Draws a single point at position ( x , y ).

PySide2.QtGui.QPainter. drawPoints ( points )
参数

points QPolygonF

PySide2.QtGui.QPainter. drawPoints ( points )
参数

points QPolygon

PySide2.QtGui.QPainter. drawPoints ( arg__1 )
参数

arg__1

PySide2.QtGui.QPainter. drawPoints ( arg__1 )
参数

arg__1

PySide2.QtGui.QPainter. drawPolygon ( arg__1 , arg__2 )
参数
  • arg__1

  • arg__2 FillRule

PySide2.QtGui.QPainter. drawPolygon ( arg__1 , arg__2 )
参数
  • arg__1

  • arg__2 FillRule

PySide2.QtGui.QPainter. drawPolygon ( polygon [ , fillRule=Qt.OddEvenFill ] )
参数
PySide2.QtGui.QPainter. drawPolygon ( polygon [ , fillRule=Qt.OddEvenFill ] )
参数
PySide2.QtGui.QPainter. drawPolyline ( polyline )
参数

polyline QPolygonF

PySide2.QtGui.QPainter. drawPolyline ( polygon )
参数

polygon QPolygon

PySide2.QtGui.QPainter. drawPolyline ( arg__1 )
参数

arg__1

PySide2.QtGui.QPainter. drawPolyline ( arg__1 )
参数

arg__1

PySide2.QtGui.QPainter. drawRect ( rect )
参数

rect QRect

PySide2.QtGui.QPainter. drawRect ( rect )
参数

rect QRectF

PySide2.QtGui.QPainter. drawRect ( x1 , y1 , w , h )
参数
  • x1 int

  • y1 int

  • w int

  • h int

这是重载函数。

Draws a rectangle with upper left corner at ( x , y ) and with the given width and height .

PySide2.QtGui.QPainter. drawRects ( rectangles )
参数

rectangles

PySide2.QtGui.QPainter. drawRects ( rectangles )
参数

rectangles

PySide2.QtGui.QPainter. drawRoundRect ( r [ , xround=25 [ , yround=25 ] ] )
参数
  • r QRect

  • xround int

  • yround int

注意

此函数被弃用。

PySide2.QtGui.QPainter. drawRoundRect ( r [ , xround=25 [ , yround=25 ] ] )
参数
  • r QRectF

  • xround int

  • yround int

注意

此函数被弃用。

PySide2.QtGui.QPainter. drawRoundRect ( x , y , w , h [ , xRound=25 [ , yRound=25 ] ] )
参数
  • x int

  • y int

  • w int

  • h int

  • xRound int

  • yRound int

注意

此函数被弃用。

这是重载函数。

Draws the rectangle x , y , w , h with rounded corners.

PySide2.QtGui.QPainter. drawRoundedRect ( x , y , w , h , xRadius , yRadius [ , mode=Qt.AbsoluteSize ] )
参数
  • x int

  • y int

  • w int

  • h int

  • xRadius qreal

  • yRadius qreal

  • mode SizeMode

这是重载函数。

Draws the given rectangle x , y , w , h with rounded corners.

PySide2.QtGui.QPainter. drawRoundedRect ( rect , xRadius , yRadius [ , mode=Qt.AbsoluteSize ] )
参数
  • rect QRect

  • xRadius qreal

  • yRadius qreal

  • mode SizeMode

PySide2.QtGui.QPainter. drawRoundedRect ( rect , xRadius , yRadius [ , mode=Qt.AbsoluteSize ] )
参数
  • rect QRectF

  • xRadius qreal

  • yRadius qreal

  • mode SizeMode

PySide2.QtGui.QPainter. drawStaticText ( topLeftPosition , staticText )
参数
PySide2.QtGui.QPainter. drawStaticText ( left , top , staticText )
参数

这是重载函数。

Draws the staticText at coordinates left and top .

注意

The y-position is used as the top of the font.

PySide2.QtGui.QPainter. drawStaticText ( topLeftPosition , staticText )
参数
PySide2.QtGui.QPainter. drawText ( p , s )
参数
  • p QPoint

  • s – unicode

PySide2.QtGui.QPainter. drawText ( p , s )
参数
  • p QPointF

  • s – unicode

PySide2.QtGui.QPainter. drawText ( r , flags , text )
参数
  • r QRect

  • flags int

  • text – unicode

PySide2.QtGui.QPainter. drawText ( r , text [ , o=QTextOption() ] )
参数
PySide2.QtGui.QPainter. drawText ( r , flags , text )
参数
  • r QRectF

  • flags int

  • text – unicode

PySide2.QtGui.QPainter. drawText ( x , y , s )
参数
  • x int

  • y int

  • s – unicode

PySide2.QtGui.QPainter. drawText ( x , y , w , h , flags , text )
参数
  • x int

  • y int

  • w int

  • h int

  • flags int

  • text – unicode

这是重载函数。

绘制给定 text within the rectangle with origin ( x , y ), width and height .

boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text. For example, in the following image, the dotted line represents boundingRect as calculated by the function, and the dashed line represents the rectangle defined by x , y , width and height :

qpainter-text-bounds1

QPainter painter(this);
QFont font = painter.font();
font.setPixelSize(48);
painter.setFont(font);
const QRect rectangle = QRect(0, 0, 100, 50);
QRect boundingRect;
painter.drawText(rectangle, 0, tr("Hello"), &boundingRect);
QPen pen = painter.pen();
pen.setStyle(Qt::DotLine);
painter.setPen(pen);
painter.drawRect(boundingRect.adjusted(0, 0, -pen.width(), -pen.width()));
pen.setStyle(Qt::DashLine);
painter.setPen(pen);
painter.drawRect(rectangle.adjusted(0, 0, -pen.width(), -pen.width()));
																

flags argument is a bitwise OR of the following flags:

  • AlignLeft

  • AlignRight

  • AlignHCenter

  • AlignJustify

  • AlignTop

  • AlignBottom

  • AlignVCenter

  • AlignCenter

  • TextSingleLine

  • TextExpandTabs

  • TextShowMnemonic

  • TextWordWrap

默认情况下, QPainter 绘制抗锯齿文本。

注意

The y-position is used as the top of the font.

另请参阅

AlignmentFlag TextFlag setFont() setPen()

PySide2.QtGui.QPainter. drawTextItem ( p , ti )
参数
PySide2.QtGui.QPainter. drawTextItem ( p , ti )
参数
PySide2.QtGui.QPainter. drawTextItem ( x , y , ti )
参数
PySide2.QtGui.QPainter. drawTiledPixmap ( x , y , w , h , arg__5 [ , sx=0 [ , sy=0 ] ] )
参数
  • x int

  • y int

  • w int

  • h int

  • arg__5 QPixmap

  • sx int

  • sy int

这是重载函数。

Draws a tiled pixmap in the specified rectangle.

( x , y ) specifies the top-left point in the paint device that is to be drawn onto; with the given width and height . ( sx , sy ) specifies the top-left point in the pixmap that is to be drawn; this defaults to (0, 0).

PySide2.QtGui.QPainter. drawTiledPixmap ( rect , pm [ , offset=QPointF() ] )
参数
  • rect QRectF

  • pm QPixmap

  • offset QPointF

PySide2.QtGui.QPainter. drawTiledPixmap ( arg__1 , arg__2 [ , pos=QPoint() ] )
参数
  • arg__1 QRect

  • arg__2 QPixmap

  • pos QPoint

PySide2.QtGui.QPainter. end ( )
返回类型

bool

Ends painting. Any resources used while painting are released. You don’t normally need to call this since it is called by the destructor.

返回 true if the painter is no longer active; otherwise returns false .

PySide2.QtGui.QPainter. endNativePainting ( )

Restores the painter after manually issuing native painting commands. Lets the painter restore any native state that it relies on before calling any other painter commands.

PySide2.QtGui.QPainter. eraseRect ( arg__1 )
参数

arg__1 QRect

PySide2.QtGui.QPainter. eraseRect ( arg__1 )
参数

arg__1 QRectF

PySide2.QtGui.QPainter. eraseRect ( x , y , w , h )
参数
  • x int

  • y int

  • w int

  • h int

这是重载函数。

Erases the area inside the rectangle beginning at ( x , y ) with the given width and height .

PySide2.QtGui.QPainter. fillPath ( path , brush )
参数

Fills the given path using the given brush . The outline is not drawn.

Alternatively, you can specify a QColor 而不是 QBrush ; the QBrush constructor (taking a QColor argument) will automatically create a solid pattern brush.

另请参阅

drawPath()

PySide2.QtGui.QPainter. fillRect ( arg__1 , arg__2 )
参数
PySide2.QtGui.QPainter. fillRect ( x , y , w , h , color )
参数
  • x int

  • y int

  • w int

  • h int

  • color QColor

PySide2.QtGui.QPainter. fillRect ( x , y , w , h , arg__5 )
参数
  • x int

  • y int

  • w int

  • h int

  • arg__5 QBrush

PySide2.QtGui.QPainter. fillRect ( x , y , w , h , c )
参数
  • x int

  • y int

  • w int

  • h int

  • c GlobalColor

这是重载函数。

Fills the rectangle beginning at ( x , y ) with the given width and height ,使用给定 color .

PySide2.QtGui.QPainter. fillRect ( x , y , w , h , style )
参数
  • x int

  • y int

  • w int

  • h int

  • style BrushStyle

这是重载函数。

Fills the rectangle beginning at ( x , y ) with the given width and height , using the brush style 指定。

PySide2.QtGui.QPainter. fillRect ( x , y , w , h , preset )
参数
  • x int

  • y int

  • w int

  • h int

  • preset Preset

这是重载函数。

Fills the rectangle beginning at ( x , y ) with the given width and height , using the given gradient preset .

PySide2.QtGui.QPainter. fillRect ( r , c )
参数
  • r QRectF

  • c GlobalColor

PySide2.QtGui.QPainter. fillRect ( r , style )
参数
  • r QRectF

  • style BrushStyle

PySide2.QtGui.QPainter. fillRect ( arg__1 , color )
参数
PySide2.QtGui.QPainter. fillRect ( r , c )
参数
  • r QRect

  • c GlobalColor

PySide2.QtGui.QPainter. fillRect ( r , style )
参数
  • r QRect

  • style BrushStyle

PySide2.QtGui.QPainter. fillRect ( r , preset )
参数
  • r QRect

  • preset Preset

PySide2.QtGui.QPainter. fillRect ( arg__1 , color )
参数
PySide2.QtGui.QPainter. fillRect ( arg__1 , arg__2 )
参数
PySide2.QtGui.QPainter. fillRect ( r , preset )
参数
  • r QRectF

  • preset Preset

PySide2.QtGui.QPainter. font ( )
返回类型

QFont

Returns the currently set font used for drawing text.

另请参阅

setFont() drawText() 设置

PySide2.QtGui.QPainter. fontInfo ( )
返回类型

QFontInfo

Returns the font info for the painter if the painter is active. Otherwise, the return value is undefined.

另请参阅

font() isActive() 设置

PySide2.QtGui.QPainter. fontMetrics ( )
返回类型

QFontMetrics

Returns the font metrics for the painter if the painter is active. Otherwise, the return value is undefined.

另请参阅

font() isActive() 设置

PySide2.QtGui.QPainter. hasClipping ( )
返回类型

bool

返回 true if clipping has been set; otherwise returns false .

另请参阅

setClipping() Clipping

PySide2.QtGui.QPainter. initFrom ( device )
参数

device QPaintDevice

注意

此函数被弃用。

Initializes the painters pen, background and font to the same as the given device .

另请参阅

begin() 设置

PySide2.QtGui.QPainter. isActive ( )
返回类型

bool

返回 true if begin() has been called and end() has not yet been called; otherwise returns false .

PySide2.QtGui.QPainter. layoutDirection ( )
返回类型

LayoutDirection

Returns the layout direction used by the painter when drawing text.

PySide2.QtGui.QPainter. matrix ( )
返回类型

QMatrix

注意

此函数被弃用。

使用 worldTransform() 代替。

PySide2.QtGui.QPainter. matrixEnabled ( )
返回类型

bool

注意

此函数被弃用。

使用 worldMatrixEnabled() instead

PySide2.QtGui.QPainter. opacity ( )
返回类型

qreal

返回描绘器的不透明度。默认值为 1。

另请参阅

setOpacity()

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

QPaintEngine

Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0.

另请参阅

isActive()

PySide2.QtGui.QPainter. pen ( )
返回类型

QPen

Returns the painter’s current pen.

另请参阅

setPen() 设置

static PySide2.QtGui.QPainter. redirected ( device [ , offset=None ] )
参数
返回类型

QPaintDevice

注意

此函数被弃用。

使用 render() obsoletes the use of this function.

Returns the replacement for given device . The optional out parameter offset returns the offset within the replaced device.

警告

Making use of redirections in the QPainter API implies that begin() and QPaintDevice destructors need to hold a mutex for a short period. This can impact performance. Use of render is strongly encouraged.

PySide2.QtGui.QPainter. renderHints ( )
返回类型

RenderHints

Returns a flag that specifies the rendering hints that are set for this painter.

另请参阅

setRenderHints() testRenderHint() 渲染 Quality

PySide2.QtGui.QPainter. resetMatrix ( )

注意

此函数被弃用。

Resets any transformations that were made using translate() , scale() , shear() , rotate() , setWorldMatrix() , setViewport() and setWindow() .

It is advisable to use resetTransform() instead of this function to preserve the properties of perspective transformations.

另请参阅

Coordinate 变换

PySide2.QtGui.QPainter. resetTransform ( )

Resets any transformations that were made using translate() , scale() , shear() , rotate() , setWorldTransform() , setViewport() and setWindow() .

另请参阅

Coordinate 变换

PySide2.QtGui.QPainter. restore ( )

Restores the current painter state (pops a saved state off the stack).

另请参阅

save()

static PySide2.QtGui.QPainter. restoreRedirected ( device )
参数

device QPaintDevice

注意

此函数被弃用。

使用 render() obsoletes the use of this function.

Restores the previous redirection for the given device after a call to setRedirected() .

警告

Making use of redirections in the QPainter API implies that begin() and QPaintDevice destructors need to hold a mutex for a short period. This can impact performance. Use of render is strongly encouraged.

另请参阅

redirected()

PySide2.QtGui.QPainter. rotate ( a )
参数

a qreal

Rotates the coordinate system clockwise. The given angle parameter is in degrees.

另请参阅

setWorldTransform() Coordinate 变换

PySide2.QtGui.QPainter. save ( )

Saves the current painter state (pushes the state onto a stack). A must be followed by a corresponding restore() ; the end() function unwinds the stack.

另请参阅

restore()

PySide2.QtGui.QPainter. scale ( sx , sy )
参数
  • sx qreal

  • sy qreal

Scales the coordinate system by ( sx , sy ).

另请参阅

setWorldTransform() Coordinate 变换

PySide2.QtGui.QPainter. setBackground ( bg )
参数

bg QBrush

将描绘器背景笔刷设为给定 brush .

The background brush is the brush that is filled in when drawing opaque text, stippled lines and bitmaps. The background brush has no effect in transparent background mode (which is the default).

PySide2.QtGui.QPainter. setBackgroundMode ( mode )
参数

mode BGMode

将描绘器背景模式设为给定 mode

TransparentMode (默认) 绘制点画线和文本无需设置背景像素。 OpaqueMode 填充这些空间采用当前背景色。

注意:为绘制透明位图或像素图,必须使用 setMask() .

PySide2.QtGui.QPainter. setBrush ( style )
参数

style BrushStyle

这是重载函数。

Sets the painter’s brush to black color and the specified style .

PySide2.QtGui.QPainter. setBrush ( brush )
参数

brush QBrush

PySide2.QtGui.QPainter. setBrushOrigin ( arg__1 )
参数

arg__1 QPoint

PySide2.QtGui.QPainter. setBrushOrigin ( arg__1 )
参数

arg__1 QPointF

PySide2.QtGui.QPainter. setBrushOrigin ( x , y )
参数
  • x int

  • y int

这是重载函数。

Sets the brush’s origin to point ( x , y ).

PySide2.QtGui.QPainter. setClipPath ( path [ , op=Qt.ReplaceClip ] )
参数

Enables clipping, and sets the clip path for the painter to the given path , with the clip operation .

Note that the clip path is specified in logical (painter) coordinates.

另请参阅

clipPath() clipRegion() Clipping

PySide2.QtGui.QPainter. setClipRect ( arg__1 [ , op=Qt.ReplaceClip ] )
参数
  • arg__1 QRect

  • op ClipOperation

PySide2.QtGui.QPainter. setClipRect ( x , y , w , h [ , op=Qt.ReplaceClip ] )
参数
  • x int

  • y int

  • w int

  • h int

  • op ClipOperation

Enables clipping, and sets the clip region to the rectangle beginning at ( x , y ) with the given width and height .

PySide2.QtGui.QPainter. setClipRect ( arg__1 [ , op=Qt.ReplaceClip ] )
参数
  • arg__1 QRectF

  • op ClipOperation

PySide2.QtGui.QPainter. setClipRegion ( arg__1 [ , op=Qt.ReplaceClip ] )
参数

Sets the clip region to the given region using the specified clip operation . The default clip operation is to replace the current clip region.

Note that the clip region is given in logical coordinates.

另请参阅

clipRegion() setClipRect() Clipping

PySide2.QtGui.QPainter. setClipping ( enable )
参数

enable bool

Enables clipping if enable is true, or disables clipping if enable is false.

另请参阅

hasClipping() Clipping

PySide2.QtGui.QPainter. setCompositionMode ( mode )
参数

mode CompositionMode

将合成模式设为给定 mode .

警告

Only a QPainter operating on a QImage fully supports all composition modes. The RasterOp modes are supported for X11 as described in compositionMode() .

另请参阅

compositionMode()

PySide2.QtGui.QPainter. setFont ( f )
参数

f QFont

Sets the painter’s font to the given font .

This font is used by subsequent drawText() functions. The text color is the same as the pen color.

If you set a font that isn’t available, Qt finds a close match. font() will return what you set using and fontInfo() returns the font actually being used (which may be the same).

另请参阅

font() drawText() 设置

PySide2.QtGui.QPainter. setLayoutDirection ( direction )
参数

direction LayoutDirection

Sets the layout direction used by the painter when drawing text, to the specified direction .

默认为 LayoutDirectionAuto , which will implicitly determine the direction from the text drawn.

PySide2.QtGui.QPainter. setMatrix ( matrix [ , combine=false ] )
参数

注意

此函数被弃用。

使用 setWorldTransform() 代替。

PySide2.QtGui.QPainter. setMatrixEnabled ( enabled )
参数

enabled bool

注意

此函数被弃用。

使用 setWorldMatrixEnabled() 代替。

PySide2.QtGui.QPainter. setOpacity ( opacity )
参数

opacity qreal

把描绘器的不透明度设为 opacity . The value should be in the range 0.0 to 1.0, where 0.0 is fully transparent and 1.0 is fully opaque.

Opacity set on the painter will apply to all drawing operations individually.

另请参阅

opacity()

PySide2.QtGui.QPainter. setPen ( pen )
参数

pen QPen

PySide2.QtGui.QPainter. setPen ( color )
参数

color QColor

PySide2.QtGui.QPainter. setPen ( style )
参数

style PenStyle

这是重载函数。

Sets the painter’s pen to have the given style , width 1 and black color.

static PySide2.QtGui.QPainter. setRedirected ( device , replacement [ , offset=QPoint() ] )
参数

注意

此函数被弃用。

Please use render() 代替。

Redirects all paint commands for the given paint device , to the replacement device. The optional point offset defines an offset within the source device.

The redirection will not be effective until the begin() function has been called; make sure to call end() 为给定 device ‘s painter (if any) before redirecting. Call restoreRedirected() to restore the previous redirection.

警告

Making use of redirections in the QPainter API implies that begin() and QPaintDevice destructors need to hold a mutex for a short period. This can impact performance. Use of render is strongly encouraged.

PySide2.QtGui.QPainter. setRenderHint ( hint [ , on=true ] )
参数

Sets the given render hint on the painter if on is true; otherwise clears the render hint.

另请参阅

setRenderHints() renderHints() 渲染 Quality

PySide2.QtGui.QPainter. setRenderHints ( hints [ , on=true ] )
参数
  • hints RenderHints

  • on bool

Sets the given render hints on the painter if on is true; otherwise clears the render hints.

另请参阅

setRenderHint() renderHints() 渲染 Quality

PySide2.QtGui.QPainter. setTransform ( transform [ , combine=false ] )
参数

Sets the world transformation matrix. If combine is true, the specified transform is combined with the current matrix; otherwise it replaces the current matrix.

PySide2.QtGui.QPainter. setViewTransformEnabled ( enable )
参数

enable bool

Enables view transformations if enable is true, or disables view transformations if enable is false.

PySide2.QtGui.QPainter. setViewport ( 视口 )
参数

视口 QRect

Sets the painter’s viewport rectangle to the given rectangle , and enables view transformations.

The viewport rectangle is part of the view transformation. The viewport specifies the device coordinate system. Its sister, the window() , specifies the logical coordinate system.

The default viewport rectangle is the same as the device’s rectangle.

PySide2.QtGui.QPainter. setViewport ( x , y , w , h )
参数
  • x int

  • y int

  • w int

  • h int

这是重载函数。

Sets the painter’s viewport rectangle to be the rectangle beginning at ( x , y ) with the given width and height .

PySide2.QtGui.QPainter. setWindow ( window )
参数

window QRect

Sets the painter’s window to the given rectangle , and enables view transformations.

The window rectangle is part of the view transformation. The window specifies the logical coordinate system. Its sister, the viewport() , specifies the device coordinate system.

The default window rectangle is the same as the device’s rectangle.

PySide2.QtGui.QPainter. setWindow ( x , y , w , h )
参数
  • x int

  • y int

  • w int

  • h int

这是重载函数。

Sets the painter’s window to the rectangle beginning at ( x , y ) and the given width and height .

PySide2.QtGui.QPainter. setWorldMatrix ( matrix [ , combine=false ] )
参数

注意

此函数被弃用。

Sets the transformation matrix to matrix and enables transformations.

注意

It is advisable to use setWorldTransform() instead of this function to preserve the properties of perspective transformations.

combine is true, then matrix is combined with the current transformation matrix; otherwise matrix replaces the current transformation matrix.

matrix is the identity matrix and combine is false, this function calls setWorldMatrixEnabled (false). (The identity matrix is the matrix where m11() and m22() are 1.0 and the rest are 0.0.)

The following functions can transform the coordinate system without using a QMatrix :

They operate on the painter’s worldMatrix() and are implemented like this:

def rotate(self, angle):
    matrix = QMatrix()
    matrix.rotate(angle)
    setWorldMatrix(matrix, true)
												

Note that when using function you should always have combine be true when you are drawing into a QPicture . Otherwise it may not be possible to replay the picture with additional transformations; using the translate() , scale() , etc. convenience functions is safe.

For more information about the coordinate system, transformations and window-viewport conversion, see 坐标系统 .

PySide2.QtGui.QPainter. setWorldMatrixEnabled ( enabled )
参数

enabled bool

Enables transformations if enable is true, or disables transformations if enable is false. The world transformation matrix is not changed.

另请参阅

worldMatrixEnabled() worldTransform() Coordinate 变换

PySide2.QtGui.QPainter. setWorldTransform ( matrix [ , combine=false ] )
参数

Sets the world transformation matrix. If combine is true, the specified matrix is combined with the current matrix; otherwise it replaces the current matrix.

PySide2.QtGui.QPainter. shear ( sh , sv )
参数
  • sh qreal

  • sv qreal

Shears the coordinate system by ( sh , sv ).

另请参阅

setWorldTransform() Coordinate 变换

PySide2.QtGui.QPainter. strokePath ( path , pen )
参数

Draws the outline (strokes) the path path with the pen specified by pen

另请参阅

fillPath() 绘制

PySide2.QtGui.QPainter. testRenderHint ( hint )
参数

hint RenderHint

返回类型

bool

返回 true if hint 已设置;否则返回 false .

PySide2.QtGui.QPainter. transform ( )
返回类型

QTransform

别名为 worldTransform() . Returns the world transformation matrix.

PySide2.QtGui.QPainter. translate ( offset )
参数

offset QPoint

PySide2.QtGui.QPainter. translate ( offset )
参数

offset QPointF

PySide2.QtGui.QPainter. translate ( dx , dy )
参数
  • dx qreal

  • dy qreal

这是重载函数。

Translates the coordinate system by the vector ( dx , dy ).

PySide2.QtGui.QPainter. viewTransformEnabled ( )
返回类型

bool

返回 true if view transformation is enabled; otherwise returns false.

PySide2.QtGui.QPainter. 视口 ( )
返回类型

QRect

Returns the viewport rectangle.

PySide2.QtGui.QPainter. window ( )
返回类型

QRect

Returns the window rectangle.

PySide2.QtGui.QPainter. worldMatrix ( )
返回类型

QMatrix

注意

此函数被弃用。

Returns the world transformation matrix.

It is advisable to use worldTransform() because does not preserve the properties of perspective transformations.

另请参阅

setWorldMatrix() Coordinate 变换 坐标系统

PySide2.QtGui.QPainter. worldMatrixEnabled ( )
返回类型

bool

返回 true if world transformation is enabled; otherwise returns false.

PySide2.QtGui.QPainter. worldTransform ( )
返回类型

QTransform

Returns the world transformation matrix.