|  | Home · All Classes · Modules

# QPainter Class Reference
[QtGui module]

The QPainter class performs low-level painting on widgets and other paint devices. More...

Inherited by QStylePainter.

### Types

- enum CompositionMode { CompositionMode_SourceOver, CompositionMode_DestinationOver, CompositionMode_Clear, CompositionMode_Source, ..., CompositionMode_Exclusion }
- enum RenderHint { Antialiasing, TextAntialiasing, SmoothPixmapTransform, HighQualityAntialiasing }
- class RenderHints

### Methods

- __init__ (self)
- __init__ (self, QPaintDevice)
- QBrush background (self)
- Qt.BGMode backgroundMode (self)
- bool begin (self, QPaintDevice)
- QRectF boundingRect (self, QRectF rect, int flags, QString text)
- QRect boundingRect (self, QRect rect, int flags, QString text)
- QRectF boundingRect (self, QRectF rect, QString text, QTextOption o = QTextOption())
- QRect boundingRect (self, int x, int y, int w, int h, int flags, QString text)
- QBrush brush (self)
- QPoint brushOrigin (self)
- QPainterPath clipPath (self)
- QRegion clipRegion (self)
- QMatrix combinedMatrix (self)
- QTransform combinedTransform (self)
- CompositionMode compositionMode (self)
- QPaintDevice device (self)
- QMatrix deviceMatrix (self)
- QTransform deviceTransform (self)
- drawArc (self, QRectF rect, int a, int alen)
- drawArc (self, QRect r, int a, int alen)
- drawArc (self, int x, int y, int w, int h, int a, int alen)
- drawChord (self, QRectF rect, int a, int alen)
- drawChord (self, QRect rect, int a, int alen)
- drawChord (self, int x, int y, int w, int h, int a, int alen)
- drawConvexPolygon (self, QPointF point, ...)
- drawConvexPolygon (self, QPolygonF poly)
- drawConvexPolygon (self, QPoint point, ...)
- drawConvexPolygon (self, QPolygon poly)
- drawEllipse (self, QRectF r)
- drawEllipse (self, QRect r)
- drawEllipse (self, int x, int y, int w, int h)
- drawImage (self, QRectF targetRect, QImage image, QRectF sourceRect, Qt.ImageConversionFlags flags = Qt.AutoColor)
- drawImage (self, QRect targetRect, QImage image, QRect sourceRect, Qt.ImageConversionFlags flags = Qt.AutoColor)
- drawImage (self, QPointF p, QImage image, QRectF sr, Qt.ImageConversionFlags flags = Qt.AutoColor)
- drawImage (self, QPoint p, QImage image, QRect sr, Qt.ImageConversionFlags flags = Qt.AutoColor)
- drawImage (self, QRectF r, QImage image)
- drawImage (self, QRect r, QImage image)
- drawImage (self, QPointF p, QImage image)
- drawImage (self, QPoint p, QImage image)
- drawImage (self, int x, int y, QImage image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt.ImageConversionFlags flags = Qt.AutoColor)
- drawLine (self, QLineF l)
- drawLine (self, QLine line)
- drawLine (self, int x1, int y1, int x2, int y2)
- drawLine (self, QPoint p1, QPoint p2)
- drawLine (self, QPointF p1, QPointF p2)
- drawLines (self, QLineF line, ...)
- drawLines (self, QLineF-list lines)
- drawLines (self, QPointF pointPair, ...)
- drawLines (self, QPointF-list pointPairs)
- drawLines (self, QLine line, ...)
- drawLines (self, QLine-list lines)
- drawLines (self, QPoint pointPair, ...)
- drawLines (self, QPoint-list pointPairs)
- drawPath (self, QPainterPath path)
- drawPicture (self, QPointF p, QPicture picture)
- drawPicture (self, int x, int y, QPicture p)
- drawPicture (self, QPoint pt, QPicture p)
- drawPie (self, QRectF rect, int a, int alen)
- drawPie (self, QRect rect, int a, int alen)
- drawPie (self, int x, int y, int w, int h, int a, int alen)
- drawPixmap (self, QRectF targetRect, QPixmap pixmap, QRectF sourceRect)
- drawPixmap (self, QRect targetRect, QPixmap pixmap, QRect sourceRect)
- drawPixmap (self, QPointF p, QPixmap pm)
- drawPixmap (self, QPoint p, QPixmap pm)
- drawPixmap (self, QRect r, QPixmap pm)
- drawPixmap (self, int x, int y, QPixmap pm)
- drawPixmap (self, int x, int y, int w, int h, QPixmap pm)
- drawPixmap (self, int x, int y, int w, int h, QPixmap pm, int sx, int sy, int sw, int sh)
- drawPixmap (self, int x, int y, QPixmap pm, int sx, int sy, int sw, int sh)
- drawPixmap (self, QPointF p, QPixmap pm, QRectF sr)
- drawPixmap (self, QPoint p, QPixmap pm, QRect sr)
- drawPoint (self, QPointF p)
- drawPoint (self, int x, int y)
- drawPoint (self, QPoint p)
- drawPoints (self, QPointF point, ...)
- drawPoints (self, QPolygonF points)
- drawPoints (self, QPoint point, ...)
- drawPoints (self, QPolygon points)
- drawPolygon (self, QPointF point, ...)
- drawPolygon (self, QPolygonF polygon, Qt.FillRule fillRule = Qt.OddEvenFill)
- drawPolygon (self, QPoint point, ...)
- drawPolygon (self, QPolygon polygon, Qt.FillRule fillRule = Qt.OddEvenFill)
- drawPolyline (self, QPointF point, ...)
- drawPolyline (self, QPolygonF polyline)
- drawPolyline (self, QPoint point, ...)
- drawPolyline (self, QPolygon polyline)
- drawRect (self, QRectF rect)
- drawRect (self, int x, int y, int w, int h)
- drawRect (self, QRect r)
- drawRects (self, QRectF rect, ...)
- drawRects (self, QRectF-list rects)
- drawRects (self, QRect rect, ...)
- drawRects (self, QRect-list rects)
- drawRoundRect (self, QRectF r, int xround = 25, int yround = 25)
- drawRoundRect (self, int x, int y, int w, int h, int xRnd = 25, int yRnd = 25)
- drawRoundRect (self, QRect rect, int xRnd = 25, int yRnd = 25)
- drawText (self, QPointF p, QString s)
- QRectF br drawText (self, QRectF r, int flags, QString text)
- QRect br drawText (self, QRect r, int flags, QString text)
- drawText (self, QRectF r, QString text, QTextOption o = QTextOption())
- drawText (self, QPoint p, QString s)
- QRect br drawText (self, int x, int y, int w, int h, int flags, QString str)
- drawText (self, int x, int y, QString s)
- drawTiledPixmap (self, QRectF rect, QPixmap pm, QPointF offset = QPointF())
- drawTiledPixmap (self, QRect rect, QPixmap pm, QPoint offset = QPoint())
- drawTiledPixmap (self, int x, int y, int w, int h, QPixmap pm, int sx = 0, int sy = 0)
- bool end (self)
- eraseRect (self, QRectF)
- eraseRect (self, QRect rect)
- eraseRect (self, int x, int y, int w, int h)
- fillPath (self, QPainterPath path, QBrush brush)
- fillRect (self, QRectF, QBrush)
- fillRect (self, QRect, QBrush)
- fillRect (self, int x, int y, int w, int h, QBrush b)
- QFont font (self)
- QFontInfo fontInfo (self)
- QFontMetrics fontMetrics (self)
- bool hasClipping (self)
- initFrom (self, QWidget widget)
- bool isActive (self)
- Qt.LayoutDirection layoutDirection (self)
- QMatrix matrix (self)
- bool matrixEnabled (self)
- float opacity (self)
- QPaintEngine paintEngine (self)
- QPen pen (self)
- RenderHints renderHints (self)
- resetMatrix (self)
- resetTransform (self)
- restore (self)
- rotate (self, float a)
- save (self)
- scale (self, float sx, float sy)
- setBackground (self, QBrush bg)
- setBackgroundMode (self, Qt.BGMode mode)
- setBrush (self, QBrush brush)
- setBrush (self, Qt.BrushStyle style)
- setBrushOrigin (self, QPointF)
- setBrushOrigin (self, int x, int y)
- setBrushOrigin (self, QPoint p)
- setClipPath (self, QPainterPath path, Qt.ClipOperation op = Qt.ReplaceClip)
- setClipping (self, bool enable)
- setClipRect (self, QRectF, Qt.ClipOperation op = Qt.ReplaceClip)
- setClipRect (self, int x, int y, int w, int h, Qt.ClipOperation op = Qt.ReplaceClip)
- setClipRect (self, QRect rect, Qt.ClipOperation op = Qt.ReplaceClip)
- setClipRegion (self, QRegion, Qt.ClipOperation op = Qt.ReplaceClip)
- setCompositionMode (self, CompositionMode mode)
- setFont (self, QFont f)
- setLayoutDirection (self, Qt.LayoutDirection direction)
- setMatrix (self, QMatrix matrix, bool combine = False)
- setMatrixEnabled (self, bool enabled)
- setOpacity (self, float opacity)
- setPen (self, QColor color)
- setPen (self, QPen pen)
- setPen (self, Qt.PenStyle style)
- setRenderHint (self, RenderHint hint, bool on = True)
- setRenderHints (self, RenderHints hints, bool on = True)
- setTransform (self, QTransform transform, bool combine = False)
- setViewport (self, QRect viewport)
- setViewport (self, int x, int y, int w, int h)
- setViewTransformEnabled (self, bool enable)
- setWindow (self, QRect window)
- setWindow (self, int x, int y, int w, int h)
- setWorldMatrix (self, QMatrix matrix, bool combine = False)
- setWorldMatrixEnabled (self, bool enabled)
- setWorldTransform (self, QTransform matrix, bool combine = False)
- shear (self, float sh, float sv)
- strokePath (self, QPainterPath path, QPen pen)
- bool testRenderHint (self, RenderHint hint)
- QTransform transform (self)
- translate (self, QPointF offset)
- translate (self, float dx, float dy)
- translate (self, QPoint offset)
- QRect viewport (self)
- bool viewTransformEnabled (self)
- QRect window (self)
- QMatrix worldMatrix (self)
- bool worldMatrixEnabled (self)
- QTransform worldTransform (self)

### Static Methods

- QPaintDevice redirected (QPaintDevice device, QPoint offset = None)
- restoreRedirected (QPaintDevice device)
- setRedirected (QPaintDevice device, QPaintDevice replacement, QPoint offset = QPoint())

## Detailed Description

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

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 class.

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:

     void SimpleExampleWidget.paintEvent(QPaintEvent *)
     {
         QPainter painter(this);
         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.

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

Together with the 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 provides the interface that the painter uses to draw onto different types of devices. If the painter is active, 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 Paint System documentation.

Sometimes it is desirable to make someone else paint on an unusual QPaintDevice. QPainter supports a static function to do this, setRedirected().

Warning: When the paintdevice is a widget, QPainter can only be used inside a paintEvent() function or in a function called by paintEvent(); that is unless the Qt.WA_PaintOutsidePaintEvent widget attribute is set. On Mac OS X and Windows, you can only paint in a paintEvent() function regardless of this attribute's setting.

- Settings
- Drawing
- Rendering Quality
- Coordinate Transformations
- Clipping
- Composition Modes

### Settings

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

- font() is the font used for drawing text. If the painter isActive(), you can retrieve information about the currently set font, and its metrics, using the fontInfo() and fontMetrics() functions respectively.
- brush() defines the color or pattern that is used for filling shapes.
- pen() defines the color or stipple that is used for drawing lines or boundaries.
- backgroundMode() defines whether there is a background() or not, i.e it is either Qt.OpaqueMode or Qt.TransparentMode.
- background() only applies when backgroundMode() is Qt.OpaqueMode and pen() is a stipple. In that case, it describes the color of the background pixels in the stipple.
- brushOrigin() defines the origin of the tiled brushes, normally the origin of widget's background.
- viewport(), window(), worldMatrix() make up the painter's coordinate transformation system. For more information, see the Coordinate Transformations section and the The Coordinate System documentation.
- hasClipping() tells whether the painter clips at all. (The paint device clips, too.) If the painter clips, it clips to clipRegion().
- layoutDirection() defines the layout direction used by the painter when drawing text.
- matrixEnabled() tells whether world transformation is enabled.
- viewTransformEnabled() tells whether view transformation is enabled.

Note that some of these settings mirror settings in some paint devices, e.g. QWidget.font(). The QPainter.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.

### Drawing

QPainter provides functions to draw most primitives: drawPoint(), drawPoints(), drawLine(), drawRect(), drawRoundRect(), 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 using the current pen and brush.

The QPainter class also provides the fillRect() function which fills the given QRect, with the given QBrush, and the eraseRect() function that erases the area inside the given rectangle.

All of these functions have both integer and floating point versions.

| Basic Drawing Example The Basic Drawing example shows how to display basic graphics primitives in a variety of styles using the QPainter class.

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

Painter Paths example The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused. The Painter Paths example shows how painter paths can be used to build complex shapes for rendering. |

QPainter also provides the fillPath() function which fills the given QPainterPath with the given QBrush, and the strokePath() function that draws the outline of the given path (i.e. strokes the path).

See also the Vector Deformation demo which shows how to use advanced vector techniques to draw text using a QPainterPath, the Gradients demo which shows the different types of gradients that are available in Qt, and the Path Stroking demo which shows Qt's built-in dash patterns and shows how custom patterns can be used to extend the range of available patterns.

Vector Deformation | Gradients | Path Stroking
--- | --- | ---

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.

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

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

### Rendering Quality

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.

The 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 QPainter.AntiAliasing render hint.

| Concentric Circles Example The 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.

The RenderHint enum specifies 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, and the QPainter.SmoothPixmapTransform indicates that the engine should use a smooth pixmap transformation algorithm. HighQualityAntialiasing is an OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.

The 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.

### Coordinate Transformations

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

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 Affine Transformations demo for a visualization of a sheared coordinate system.

See also the Transformations 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.

Affine Transformations Demo The Affine Transformations demo show 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. |

All the tranformation operations operate on the transformation worldMatrix(). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see the The Coordinate System and QMatrix documentation.

The setWorldMatrix() function can replace or add to the currently set worldMatrix(). The resetMatrix() function resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow() functions. The deviceMatrix() 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 combinedMatrix(), a combination of viewport() and window() and worldMatrix(). The viewport() represents the physical coordinates specifying an arbitrary rectangle, the window() describes the same rectangle in logical coordinates, and the worldMatrix() is identical with the transformation matrix.

See also The Coordinate System documentation.

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

### Composition Modes

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 grahic 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, affectively clearing those, while the primitive only overwrites its own area.

| Composition Modes Demo The Composition Modes demo, available in Qt's demo directory, allows you to experiment with the various composition modes and see the results immediately.

See also QPaintDevice, QPaintEngine, QtSvg Module, and Basic Drawing Example.

## Type Documentation

### QPainter.CompositionMode

Defines the Porter-Duff rules 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.

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.

When the paint device is a QImage, the image format must be set to Format_ARGB32Premultiplied or Format_ARGB32 for the composition modes to have any effect. For performance the premultiplied version is the preferred format.

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

Constant | Value | Description
--- | --- | ---
`QPainter.CompositionMode_SourceOver` | `0` | This is the default mode. The alpha of the source is used to blend the pixel on top of the destination.
`QPainter.CompositionMode_DestinationOver` | `1` | The alpha of the destination is used to blend it on top of the source pixels. This mode is the inverse of CompositionMode_SourceOver.
`QPainter.CompositionMode_Clear` | `2` | The pixels in the destination are cleared (set to fully transparent) independent of the source.
`QPainter.CompositionMode_Source` | `3` | 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` | `4` | The output is the destination pixel. This means that the blending has no effect. This mode is the inverse of CompositionMode_Source.
`QPainter.CompositionMode_SourceIn` | `5` | The output is the source, where the alpha is reduced by that of the destination.
`QPainter.CompositionMode_DestinationIn` | `6` | The output is the destination, where the alpha is reduced by that of the source. This mode is the inverse of CompositionMode_SourceIn.
`QPainter.CompositionMode_SourceOut` | `7` | The output is the source, where the alpha is reduced by the inverse of destination.
`QPainter.CompositionMode_DestinationOut` | `8` | The output is the destination, where the alpha is reduced by the inverse of the source. This mode is the inverse of CompositionMode_SourceOut.
`QPainter.CompositionMode_SourceAtop` | `9` | 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` | `10` | 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 CompositionMode_SourceAtop.
`QPainter.CompositionMode_Xor` | `11` | 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. CompositionMode_Xor is not the same as the bitwise Xor.
`QPainter.CompositionMode_Plus` | `12` | Both the alpha and color of the source and destination pixels are added together.
`QPainter.CompositionMode_Multiply` | `13` | 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` | `14` | 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` | `15` | 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` | `16` | The darker of the source and destination colors is selected.
`QPainter.CompositionMode_Lighten` | `17` | The lighter of the source and destination colors is selected.
`QPainter.CompositionMode_ColorDodge` | `18` | The destination color is brightened to reflect the source color. A black source color leaves the destination color unchanged.
`QPainter.CompositionMode_ColorBurn` | `19` | The destination color is darkened to reflect the source color. A white source color leaves the destination color unchanged.
`QPainter.CompositionMode_HardLight` | `20` | 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` | `21` | Darkens or lightens the colors depending on the source color. Similar to CompositionMode_HardLight.
`QPainter.CompositionMode_Difference` | `22` | 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` | `23` | Similar to CompositionMode_Difference, but with a lower contrast. Painting with white inverts the destination color, whereas painting with black leaves the destination color unchanged.

See also compositionMode(), setCompositionMode(), Composition Modes, and Image Composition Example.

### QPainter.RenderHint

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

Constant | Value | Description
--- | --- | ---
`QPainter.Antialiasing` | `0x01` | Indicates that the engine should antialias edges of primitives if possible.
`QPainter.TextAntialiasing` | `0x02` | Indicates that the engine should antialias text if possible.
`QPainter.SmoothPixmapTransform` | `0x04` | Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.
`QPainter.HighQualityAntialiasing` | `0x08` | An OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.

The RenderHints type is a typedef for QFlags<RenderHint>. It stores an OR combination of RenderHint values.

See also renderHints(), setRenderHint(), Rendering Quality, and Concentric Circles Example.

## Method Documentation

### QPainter.__init__ (self)

Constructs a painter.

See also begin() and end().

### QPainter.__init__ (self, QPaintDevice)

Constructs a painter that begins painting the paint device immediately.

This constructor is convenient for short-lived painters, e.g. in a QWidget.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():

     void MyWidget.paintEvent(QPaintEvent *)
     {
         QPainter p;
         p.begin(this);
         p.drawLine(...);        // drawing code
         p.end();
     }

The same example using this constructor:

     void MyWidget.paintEvent(QPaintEvent *)
     {
         QPainter p(this);
         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.

See also begin() and end().

### QBrush QPainter.background (self)

Returns the current background brush.

See also setBackground() and Settings.

### Qt.BGMode QPainter.backgroundMode (self)

Returns the current background mode.

See also setBackgroundMode() and Settings.

### bool QPainter.begin (self, QPaintDevice)

Begins painting the paint device and returns true if successful; otherwise returns false.

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

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

     painter->begin(0); // impossible - paint device cannot be 0

     QPixmap image(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 begin(), and that end() is automatically done at destruction.

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

See also end() and QPainter().

### QRectF QPainter.boundingRect (self, QRectF rect, int flags, QString text)

Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font(); i.e the function tells you where the drawText() function will draw when given the same arguments.

If the text does not fit within the given rectangle using the specified flags, the function returns the required rectangle.

The flags argument is a bitwise OR of the following flags:

- Qt.AlignLeft
- Qt.AlignRight
- Qt.AlignHCenter
- Qt.AlignTop
- Qt.AlignBottom
- Qt.AlignVCenter
- Qt.AlignCenter
- Qt.TextSingleLine
- Qt.TextExpandTabs
- Qt.TextShowMnemonic
- Qt.TextWordWrap

If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined.

See also drawText(), Qt.Alignment, and Qt.TextFlag.

### QRect QPainter.boundingRect (self, QRect rect, int flags, QString text)

### QRectF QPainter.boundingRect (self, QRectF rect, QString text, QTextOption o = QTextOption())

### QRect QPainter.boundingRect (self, int x, int y, int w, int h, int flags, QString text)

This is an overloaded member function, provided for convenience.

Returns the bounding rectangle of the text as it will appear when drawn inside the given rectangle with the specified flags using the currently set font().

### QBrush QPainter.brush (self)

Returns the painter's current brush.

See also QPainter.setBrush() and Settings.

### QPoint QPainter.brushOrigin (self)

Returns the currently set brush origin.

See also setBrushOrigin() and Settings.

### QPainterPath QPainter.clipPath (self)

Returns the currently clip as a path. Note that the clip path is given in logical coordinates.

See also setClipPath(), clipRegion(), and setClipping().

### QRegion QPainter.clipRegion (self)

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

See also setClipRegion(), clipPath(), and setClipping().

### QMatrix QPainter.combinedMatrix (self)

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.

This function was introduced in Qt 4.2.

See also setWorldMatrix(), setWindow(), and setViewport().

### QTransform QPainter.combinedTransform (self)

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

See also setWorldMatrix(), setWindow(), and setViewport().

### CompositionMode QPainter.compositionMode (self)

Returns the current composition mode.

See also CompositionMode and setCompositionMode().

### QPaintDevice QPainter.device (self)

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

See also isActive().

### QMatrix QPainter.deviceMatrix (self)

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

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

This function is only needed when using platform painting commands on the platform dependent handle (Qt.HANDLE), and the platform does not do transformations nativly.

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

See also worldMatrix() and QPaintEngine.hasFeature().

### QTransform QPainter.deviceTransform (self)

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

This function is only needed when using platform painting commands on the platform dependent handle (Qt.HANDLE), and the platform does not do transformations nativly.

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

See also worldTransform() and QPaintEngine.hasFeature().

### QPainter.drawArc (self, QRectF rect, int a, int alen)

Draws the arc defined by the given rectangle, startAngle and spanAngle.

The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

     QRectF rectangle(10.0, 20.0, 80.0, 60.0);
     int startAngle = 30 * 16;
     int spanAngle = 120 * 16;

     QPainter painter(this);
     painter.drawArc(rectangle, startAngle, spanAngle);

See also drawPie(), drawChord(), and The Coordinate System.

### QPainter.drawArc (self, QRect r, int a, int alen)

This is an overloaded member function, provided for convenience.

Draws the arc defined by the given rectangle, startAngle and spanAngle.

### QPainter.drawArc (self, int x, int y, int w, int h, int a, int alen)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawChord (self, QRectF rect, int a, int alen)

Draws the chord defined by the given rectangle, startAngle and spanAngle. The chord is filled with the current brush().

The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

     QRectF rectangle(10.0, 20.0, 80.0, 60.0);
     int startAngle = 30 * 16;
     int spanAngle = 120 * 16;

     QPainter painter(this);
     painter.drawChord(rect, startAngle, spanAngle);

See also drawArc(), drawPie(), and The Coordinate System.

### QPainter.drawChord (self, QRect rect, int a, int alen)

This is an overloaded member function, provided for convenience.

Draws the chord defined by the given rectangle, startAngle and spanAngle.

### QPainter.drawChord (self, int x, int y, int w, int h, int a, int alen)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawConvexPolygon (self, QPointF point, ...)

Draws the convex polygon defined by the first pointCount points in the array points using the current pen.

     static const QPointF points[4] = {
         QPointF(10.0, 80.0),
         QPointF(20.0, 10.0),
         QPointF(80.0, 30.0),
         QPointF(90.0, 70.0)
     };

     QPainter painter(this);
     painter.drawConvexPolygon(points, 4);

The first point is implicitly connected to the last point, and the polygon is filled with the current brush(). If the supplied polygon is not convex, i.e. it contains at least one angle larger than 180 degrees, the results are undefined.

On some platforms (e.g. X11), the drawConvexPolygon() function can be faster than the drawPolygon() function.

See also drawPolygon(), drawPolyline(), and The Coordinate System.

### QPainter.drawConvexPolygon (self, QPolygonF poly)

This is an overloaded member function, provided for convenience.

Draws the convex polygon defined by the first pointCount points in the array points using the current pen.

### QPainter.drawConvexPolygon (self, QPoint point, ...)

This is an overloaded member function, provided for convenience.

Draws the convex polygon defined by polygon using the current pen and brush.

### QPainter.drawConvexPolygon (self, QPolygon poly)

This is an overloaded member function, provided for convenience.

Draws the convex polygon defined by polygon using the current pen and brush.

### QPainter.drawEllipse (self, QRectF r)

Draws the ellipse defined by the given rectangle.

A filled ellipse has a size of rectangle.size(). A stroked ellipse has a size of rectangle.size() plus the pen width.

     QRectF rectangle(10.0, 20.0, 80.0, 60.0);

     QPainter painter(this);
     painter.drawEllipse(rectangle);

See also drawPie() and The Coordinate System.

### QPainter.drawEllipse (self, QRect r)

This is an overloaded member function, provided for convenience.

Draws the ellipse defined by the given rectangle.

### QPainter.drawEllipse (self, int x, int y, int w, int h)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawImage (self, QRectF targetRect, QImage image, QRectF sourceRect, Qt.ImageConversionFlags flags = Qt.AutoColor)

Draws the rectangular portion source of the given image into the target rectangle in the paint device.

If the image needs to be modified to fit in a lower-resolution result (e.g. converting from 32-bit to 8-bit), use the flags to specify how you would prefer this to happen.

     QRectF target(10.0, 20.0, 80.0, 60.0);
     QRectF source(0.0, 0.0, 70.0, 40.0);
     QImage image(":/images/myImage.png");

     QPainter(this);
     painter.drawImage(target, image, source);

See also drawPixmap().

### QPainter.drawImage (self, QRect targetRect, QImage image, QRect sourceRect, Qt.ImageConversionFlags flags = Qt.AutoColor)

This is an overloaded member function, provided for convenience.

Draws the rectangular portion source of the given image into the target rectangle in the paint device.

### QPainter.drawImage (self, QPointF p, QImage image, QRectF sr, Qt.ImageConversionFlags flags = Qt.AutoColor)

This is an overloaded member function, provided for convenience.

Draws the given image at the given point.

### QPainter.drawImage (self, QPoint p, QImage image, QRect sr, Qt.ImageConversionFlags flags = Qt.AutoColor)

This is an overloaded member function, provided for convenience.

Draws the given image at the given point.

### QPainter.drawImage (self, QRectF r, QImage image)

This is an overloaded member function, provided for convenience.

Draws the rectangular portion source of the given image with its origin at the given point.

### QPainter.drawImage (self, QRect r, QImage image)

This is an overloaded member function, provided for convenience.

Draws the rectangular portion source of the given image with its origin at the given point.

### QPainter.drawImage (self, QPointF p, QImage image)

This is an overloaded member function, provided for convenience.

Draws the given image into the given rectangle.

### QPainter.drawImage (self, QPoint p, QImage image)

This is an overloaded member function, provided for convenience.

Draws the given image into the given rectangle.

### QPainter.drawImage (self, int x, int y, QImage image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt.ImageConversionFlags flags = Qt.AutoColor)

This is an overloaded member function, provided for convenience.

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.

### QPainter.drawLine (self, QLineF l)

Draws a line defined by line.

     QLineF line(10.0, 80.0, 90.0, 20.0);

     QPainter(this);
     painter.drawLine(line);

See also drawLines(), drawPolyline(), and The Coordinate System.

### QPainter.drawLine (self, QLine line)

This is an overloaded member function, provided for convenience.

Draws a line defined by line.

### QPainter.drawLine (self, int x1, int y1, int x2, int y2)

This is an overloaded member function, provided for convenience.

Draws a line from p1 to p2.

### QPainter.drawLine (self, QPoint p1, QPoint p2)

This is an overloaded member function, provided for convenience.

Draws a line from p1 to p2.

### QPainter.drawLine (self, QPointF p1, QPointF p2)

This is an overloaded member function, provided for convenience.

Draws a line from (x1, y1) to (x2, y2) and sets the current pen position to (x2, y2).

### QPainter.drawLines (self, QLineF line, ...)

Draws the first lineCount lines in the array lines using the current pen.

See also drawLine() and drawPolyline().

### QPainter.drawLines (self, QLineF-list lines)

This is an overloaded member function, provided for convenience.

Draws the first lineCount lines in the array lines using the current pen.

### QPainter.drawLines (self, QPointF pointPair, ...)

This is an overloaded member function, provided for convenience.

Draws the first lineCount lines in the array pointPairs using the current pen. The lines are specified as pairs of points so the number of entries in pointPairs must be at least lineCount * 2.

### QPainter.drawLines (self, QPointF-list pointPairs)

This is an overloaded member function, provided for convenience.

Draws the first lineCount lines in the array pointPairs using the current pen.

### QPainter.drawLines (self, QLine line, ...)

This is an overloaded member function, provided for convenience.

Draws a line for each pair of points in the vector pointPairs using the current pen. If there is an odd number of points in the array, the last point will be ignored.

### QPainter.drawLines (self, QLine-list lines)

This is an overloaded member function, provided for convenience.

Draws a line for each pair of points in the vector pointPairs using the current pen.

### QPainter.drawLines (self, QPoint pointPair, ...)

This is an overloaded member function, provided for convenience.

Draws the set of lines defined by the list lines using the current pen and brush.

### QPainter.drawLines (self, QPoint-list pointPairs)

This is an overloaded member function, provided for convenience.

Draws the set of lines defined by the list lines using the current pen and brush.

### QPainter.drawPath (self, QPainterPath path)

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

     QPainterPath path;
     path.moveTo(20, 80);
     path.lineTo(20, 30);
     path.cubicTo(80, 0, 50, 50, 80, 80);

     QPainter painter(this);
     painter.drawPath(path);

See also the Painter Paths example and the Vector Deformation demo.

### QPainter.drawPicture (self, QPointF p, QPicture picture)

Replays the given picture at the given point.

The QPicture class is a paint device that records and replays QPainter commands. A picture serializes the painter commands to an IO device in a platform-independent format. Everything that can be painted on a widget or pixmap can also be stored in a picture.

This function does exactly the same as QPicture.play() when called with point = QPoint(0, 0).

     QPicture picture;
     QPointF point(10.0, 20.0)
     picture.load("drawing.pic");

     QPainter painter(this);
     painter.drawPicture(0, 0, picture);

See also QPicture.play().

### QPainter.drawPicture (self, int x, int y, QPicture p)

This is an overloaded member function, provided for convenience.

Replays the given picture at the given point.

### QPainter.drawPicture (self, QPoint pt, QPicture p)

This is an overloaded member function, provided for convenience.

Draws the given picture at point (x, y).

### QPainter.drawPie (self, QRectF rect, int a, int alen)

Draws a pie defined by the given rectangle, startAngle and and spanAngle.

The pie is filled with the current brush().

The startAngle and spanAngle must be specified in 1/16th of a degree, i.e. a full circle equals 5760 (16 * 360). Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

     QRectF rectangle(10.0, 20.0, 80.0, 60.0);
     int startAngle = 30 * 16;
     int spanAngle = 120 * 16;

     QPainter painter(this);
     painter.drawPie(rectangle, startAngle, spanAngle);

See also drawEllipse(), drawChord(), and The Coordinate System.

### QPainter.drawPie (self, QRect rect, int a, int alen)

This is an overloaded member function, provided for convenience.

Draws a pie defined by the given rectangle, startAngle and and spanAngle.

### QPainter.drawPie (self, int x, int y, int w, int h, int a, int alen)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawPixmap (self, QRectF targetRect, QPixmap pixmap, QRectF sourceRect)

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

     QRectF target(10.0, 20.0, 80.0, 60.0);
     QRectF source(0.0, 0.0, 70.0, 40.0);
     QPixmap pixmap(":myPixmap.png");

     QPainter(this);
     painter.drawPixmap(target, image, source);

If pixmap is a QBitmap it is drawn with the bits that are "set" using the pens color. If backgroundMode is Qt.OpaqueMode, the "unset" bits are drawn using the color of the background brush; if backgroundMode is Qt.TransparentMode, the "unset" bits are transparent. Drawing bitmaps with gradient or texture colors is not supported.

See also drawImage().

### QPainter.drawPixmap (self, QRect targetRect, QPixmap pixmap, QRect sourceRect)

This is an overloaded member function, provided for convenience.

Draws the rectangular portion source of the given pixmap into the given target in the paint device.

### QPainter.drawPixmap (self, QPointF p, QPixmap pm)

This is an overloaded member function, provided for convenience.

Draws the rectangular portion source of the given pixmap with its origin at the given point.

### QPainter.drawPixmap (self, QPoint p, QPixmap pm)

This is an overloaded member function, provided for convenience.

Draws the rectangular portion source of the given pixmap with its origin at the given point.

### QPainter.drawPixmap (self, QRect r, QPixmap pm)

This is an overloaded member function, provided for convenience.

Draws the given pixmap with its origin at the given point.

### QPainter.drawPixmap (self, int x, int y, QPixmap pm)

This is an overloaded member function, provided for convenience.

Draws the given pixmap with its origin at the given point.

### QPainter.drawPixmap (self, int x, int y, int w, int h, QPixmap pm)

This is an overloaded member function, provided for convenience.

Draws the given pixmap at position (x, y).

### QPainter.drawPixmap (self, int x, int y, int w, int h, QPixmap pm, int sx, int sy, int sw, int sh)

This is an overloaded member function, provided for convenience.

Draws the given pixmap into the given rectangle.

### QPainter.drawPixmap (self, int x, int y, QPixmap pm, int sx, int sy, int sw, int sh)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawPixmap (self, QPointF p, QPixmap pm, QRectF sr)

This is an overloaded member function, provided for convenience.

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;

### QPainter.drawPixmap (self, QPoint p, QPixmap pm, QRect sr)

This is an overloaded member function, provided for convenience.

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.

### QPainter.drawPoint (self, QPointF p)

Draws a single point at the given position using the current pen's color.

See also The Coordinate System.

### QPainter.drawPoint (self, int x, int y)

This is an overloaded member function, provided for convenience.

Draws a single point at the given position using the current pen's color.

### QPainter.drawPoint (self, QPoint p)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawPoints (self, QPointF point, ...)

Draws the first pointCount points in the array points using the current pen's color.

See also The Coordinate System.

### QPainter.drawPoints (self, QPolygonF points)

This is an overloaded member function, provided for convenience.

Draws the first pointCount points in the array points using the current pen's color.

### QPainter.drawPoints (self, QPoint point, ...)

This is an overloaded member function, provided for convenience.

Draws the points in the vector points.

### QPainter.drawPoints (self, QPolygon points)

This is an overloaded member function, provided for convenience.

Draws the points in the vector points.

### QPainter.drawPolygon (self, QPointF point, ...)

Draws the polygon defined by the first pointCount points in the array points using the current pen and brush.

     static const QPointF points[4] = {
         QPointF(10.0, 80.0),
         QPointF(20.0, 10.0),
         QPointF(80.0, 30.0),
         QPointF(90.0, 70.0)
     };

     QPainter painter(this);
     painter.drawPolygon(points, 4);

The first point is implicitly connected to the last point, and the polygon is filled with the current brush().

If fillRule is Qt.WindingFill, the polygon is filled using the winding fill algorithm. If fillRule is Qt.OddEvenFill, the polygon is filled using the odd-even fill algorithm. See Qt.FillRule for a more detailed description of these fill rules.

See also drawConvexPolygon(), drawPolyline(), and The Coordinate System.

### QPainter.drawPolygon (self, QPolygonF polygon, Qt.FillRule fillRule = Qt.OddEvenFill)

This is an overloaded member function, provided for convenience.

Draws the polygon defined by the first pointCount points in the array points.

### QPainter.drawPolygon (self, QPoint point, ...)

### QPainter.drawPolygon (self, QPolygon polygon, Qt.FillRule fillRule = Qt.OddEvenFill)

### QPainter.drawPolyline (self, QPointF point, ...)

Draws the polyline defined by the first pointCount points in points using the current pen.

Note that unlike the drawPolygon() function the last point is not connected to the first, neither is the polyline filled.

     static const QPointF points[3] = {
         QPointF(10.0, 80.0),
         QPointF(20.0, 10.0),
         QPointF(80.0, 30.0),
     };

     QPainter painter(this);
     painter.drawPolyline(points, 3);

See also drawLines(), drawPolygon(), and The Coordinate System.

### QPainter.drawPolyline (self, QPolygonF polyline)

This is an overloaded member function, provided for convenience.

Draws the polyline defined by the first pointCount points in points using the current pen.

### QPainter.drawPolyline (self, QPoint point, ...)

### QPainter.drawPolyline (self, QPolygon polyline)

This is an overloaded member function, provided for convenience.

Draws the polyline defined by the given points using the current pen.

### QPainter.drawRect (self, QRectF rect)

Draws the current rectangle with the current pen and brush.

A filled rectangle has a size of rectangle.size(). A stroked rectangle has a size of rectangle.size() plus the pen width.

     QRectF rectangle(10.0, 20.0, 80.0, 60.0);

     QPainter painter(this);
     painter.drawRect(rectangle);

See also drawRects(), drawPolygon(), and The Coordinate System.

### QPainter.drawRect (self, int x, int y, int w, int h)

This is an overloaded member function, provided for convenience.

Draws the current rectangle with the current pen and brush.

### QPainter.drawRect (self, QRect r)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawRects (self, QRectF rect, ...)

Draws the first rectCount of the given rectangles using the current pen and brush.

See also drawRect().

### QPainter.drawRects (self, QRectF-list rects)

This is an overloaded member function, provided for convenience.

Draws the first rectCount of the given rectangles using the current pen and brush.

### QPainter.drawRects (self, QRect rect, ...)

This is an overloaded member function, provided for convenience.

Draws the given rectangles using the current pen and brush.

### QPainter.drawRects (self, QRect-list rects)

This is an overloaded member function, provided for convenience.

Draws the given rectangles using the current pen and brush.

### QPainter.drawRoundRect (self, QRectF r, int xround = 25, int yround = 25)

Draws a rectangle r with rounded corners.

The xRnd and yRnd arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness.

A filled rectangle has a size of r.size(). A stroked rectangle has a size of r.size() plus the pen width.

     QRectF rectangle(10.0, 20.0, 80.0, 60.0);

     QPainter painter(this);
     painter.drawRoundRect(rectangle);

See also drawRect() and QPen.

### QPainter.drawRoundRect (self, int x, int y, int w, int h, int xRnd = 25, int yRnd = 25)

This is an overloaded member function, provided for convenience.

Draws the rectangle r with rounded corners.

### QPainter.drawRoundRect (self, QRect rect, int xRnd = 25, int yRnd = 25)

This is an overloaded member function, provided for convenience.

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

### QPainter.drawText (self, QPointF p, QString s)

Draws the given text with the currently defined text direction, beginning at the given position.

This function does not handle the newline character (\n), as it cannot break text into multiple lines, and it cannot display the newline character. Use the QPainter.drawText() overload that takes a rectangle instead if you want to draw multiple lines of text with the newline character, or if you want the text to be wrapped.

Note: The y-position is used as the baseline of the font.

### QRectF br QPainter.drawText (self, QRectF r, int flags, QString text)

### QRect br QPainter.drawText (self, QRect r, int flags, QString text)

### QPainter.drawText (self, QRectF r, QString text, QTextOption o = QTextOption())

### QPainter.drawText (self, QPoint p, QString s)

### QRect br QPainter.drawText (self, int x, int y, int w, int h, int flags, QString str)

### QPainter.drawText (self, int x, int y, QString s)

### QPainter.drawTiledPixmap (self, QRectF rect, QPixmap pm, QPointF offset = QPointF())

Draws a tiled pixmap, inside the given rectangle with its origin at the given position.

Calling drawTiledPixmap() is similar to calling drawPixmap() several times to fill (tile) an area with a pixmap, but is potentially much more efficient depending on the underlying window system.

See also drawPixmap().

### QPainter.drawTiledPixmap (self, QRect rect, QPixmap pm, QPoint offset = QPoint())

This is an overloaded member function, provided for convenience.

Draws a tiled pixmap, inside the given rectangle with its origin at the given position.

### QPainter.drawTiledPixmap (self, int x, int y, int w, int h, QPixmap pm, int sx = 0, int sy = 0)

This is an overloaded member function, provided for convenience.

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

### bool QPainter.end (self)

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

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

See also begin() and isActive().

### QPainter.eraseRect (self, QRectF)

Erases the area inside the given rectangle. Equivalent to calling

     fillRect(rectangle, background()).

See also fillRect().

### QPainter.eraseRect (self, QRect rect)

This is an overloaded member function, provided for convenience.

Erases the area inside the given rectangle.

### QPainter.eraseRect (self, int x, int y, int w, int h)

This is an overloaded member function, provided for convenience.

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

### QPainter.fillPath (self, QPainterPath path, QBrush brush)

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

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

See also drawPath().

### QPainter.fillRect (self, QRectF, QBrush)

Fills the given rectangle with the given brush.

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

See also drawRect().

### QPainter.fillRect (self, QRect, QBrush)

This is an overloaded member function, provided for convenience.

Fills the given rectangle with the given brush.

### QPainter.fillRect (self, int x, int y, int w, int h, QBrush b)

This is an overloaded member function, provided for convenience.

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

### QFont QPainter.font (self)

Returns the currently set font used for drawing text.

See also setFont(), drawText(), and Settings.

### QFontInfo QPainter.fontInfo (self)

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

See also font(), isActive(), and Settings.

### QFontMetrics QPainter.fontMetrics (self)

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

See also font(), isActive(), and Settings.

### bool QPainter.hasClipping (self)

Returns true if clipping has been set; otherwise returns false.

See also setClipping() and Clipping.

### QPainter.initFrom (self, QWidget widget)

Initializes the painters pen, background and font to the same as the given widget. Call this function after begin() while the painter is active.

See also begin() and Settings.

### bool QPainter.isActive (self)

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

See also begin() and QPaintDevice.paintingActive().

### Qt.LayoutDirection QPainter.layoutDirection (self)

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

See also setLayoutDirection(), drawText(), and Settings.

### QMatrix QPainter.matrix (self)

### bool QPainter.matrixEnabled (self)

### float QPainter.opacity (self)

Returns the opacity of the painter. The default value is 1.

This function was introduced in Qt 4.2.

See also setOpacity().

### QPaintEngine QPainter.paintEngine (self)

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

See also isActive().

### QPen QPainter.pen (self)

Returns the painter's current pen.

See also setPen() and Settings.

### QPaintDevice QPainter.redirected (QPaintDevice device, QPoint offset = None)

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

See also setRedirected() and restoreRedirected().

### RenderHints QPainter.renderHints (self)

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

See also setRenderHints(), testRenderHint(), and Rendering Quality.

### QPainter.resetMatrix (self)

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.

See also Coordinate Transformations.

### QPainter.resetTransform (self)

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

See also Coordinate Transformations.

### QPainter.restore (self)

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

See also save().

### QPainter.restoreRedirected (QPaintDevice device)

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

See also redirected().

### QPainter.rotate (self, float a)

Rotates the coordinate system the given angle clockwise.

See also setWorldMatrix() and Coordinate Transformations.

### QPainter.save (self)

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

See also restore().

### QPainter.scale (self, float sx, float sy)

Scales the coordinate system by (sx, sy).

See also setWorldMatrix() and Coordinate Transformations.

### QPainter.setBackground (self, QBrush bg)

Sets the background brush of the painter to the given 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).

See also background(), setBackgroundMode(), and Settings.

### QPainter.setBackgroundMode (self, Qt.BGMode mode)

Sets the background mode of the painter to the given mode

Qt.TransparentMode (the default) draws stippled lines and text without setting the background pixels. Qt.OpaqueMode fills these space with the current background color.

Note that in order to draw a bitmap or pixmap transparently, you must use QPixmap.setMask().

See also backgroundMode(), setBackground(), and Settings.

### QPainter.setBrush (self, QBrush brush)

Sets the painter's brush to the given brush.

The painter's brush defines how shapes are filled.

See also brush() and Settings.

### QPainter.setBrush (self, Qt.BrushStyle style)

This is an overloaded member function, provided for convenience.

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

### QPainter.setBrushOrigin (self, QPointF)

Sets the brush origin to position.

The brush origin specifies the (0, 0) coordinate of the painter's brush. This setting only applies to pattern brushes and pixmap brushes.

Note that while the brushOrigin() was necessary to adopt the parent's background for a widget in Qt 3, this is no longer the case since the Qt 4 painter doesn't paint the background unless you explicitly tell it to do so by setting the widget's autoFillBackground property to true.

See also brushOrigin() and Settings.

### QPainter.setBrushOrigin (self, int x, int y)

This is an overloaded member function, provided for convenience.

Sets the brush's origin to the given position.

### QPainter.setBrushOrigin (self, QPoint p)

This is an overloaded member function, provided for convenience.

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

### QPainter.setClipPath (self, QPainterPath path, Qt.ClipOperation 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.

See also clipPath(), clipRegion(), and Clipping.

### QPainter.setClipping (self, bool enable)

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

See also hasClipping() and Clipping.

### QPainter.setClipRect (self, QRectF, Qt.ClipOperation op = Qt.ReplaceClip)

Enables clipping, and sets the clip region to the given rectangle using the given clip operation. The default operation is to replace the current clip rectangle.

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

See also clipRegion(), setClipping(), and Clipping.

### QPainter.setClipRect (self, int x, int y, int w, int h, Qt.ClipOperation op = Qt.ReplaceClip)

This is an overloaded member function, provided for convenience.

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

### QPainter.setClipRect (self, QRect rect, Qt.ClipOperation op = Qt.ReplaceClip)

This is an overloaded member function, provided for convenience.

Enables clipping, and sets the clip region to the given rectangle using the given clip operation.

### QPainter.setClipRegion (self, QRegion, Qt.ClipOperation 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.

See also clipRegion(), setClipRect(), and Clipping.

### QPainter.setCompositionMode (self, CompositionMode mode)

Sets the composition mode to the given mode.

Warning: You can only set the composition mode for QPainter objects that operates on a QImage.

See also compositionMode().

### QPainter.setFont (self, QFont f)

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 setFont() and fontInfo() returns the font actually being used (which may be the same).

See also font(), drawText(), and Settings.

### QPainter.setLayoutDirection (self, Qt.LayoutDirection direction)

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

See also layoutDirection(), drawText(), and Settings.

### QPainter.setMatrix (self, QMatrix matrix, bool combine = False)

### QPainter.setMatrixEnabled (self, bool enabled)

### QPainter.setOpacity (self, float opacity)

Sets the opacity of the painter to 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.

This function was introduced in Qt 4.2.

See also opacity().

### QPainter.setPen (self, QColor color)

Sets the painter's pen to be the given pen.

The pen defines how to draw lines and outlines, and it also defines the text color.

See also pen() and Settings.

### QPainter.setPen (self, QPen pen)

This is an overloaded member function, provided for convenience.

Sets the painter's pen to have style Qt.SolidLine, width 0 and the specified color.

### QPainter.setPen (self, Qt.PenStyle style)

This is an overloaded member function, provided for convenience.

Sets the painter's pen to have the given style, width 0 and black color.

### QPainter.setRedirected (QPaintDevice device, QPaintDevice replacement, QPoint offset = QPoint())

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() for the given device's painter (if any) before redirecting. Call restoreRedirected() to restore the previous redirection.

In general, you'll probably find that calling QPixmap.grabWidget() or QPixmap.grabWindow() is an easier solution.

See also redirected() and restoreRedirected().

### QPainter.setRenderHint (self, RenderHint hint, bool on = True)

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

See also setRenderHints(), renderHints(), and Rendering Quality.

### QPainter.setRenderHints (self, RenderHints hints, bool on = True)

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

This function was introduced in Qt 4.2.

See also setRenderHint(), renderHints(), and Rendering Quality.

### QPainter.setTransform (self, QTransform transform, bool 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.

This function has been added for compatibility with setMatrix(), but as with setMatrix() the preferred method of setting a transformation on the painter is through setWorldTransform().

This function was introduced in Qt 4.3.

See also transform().

### QPainter.setViewport (self, QRect viewport)

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.

See also viewport(), viewTransformEnabled(), and Window-Viewport Conversion.

### QPainter.setViewport (self, int x, int y, int w, int h)

This is an overloaded member function, provided for convenience.

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

### QPainter.setViewTransformEnabled (self, bool enable)

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

See also viewTransformEnabled() and Window-Viewport Conversion.

### QPainter.setWindow (self, QRect window)

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.

See also window(), viewTransformEnabled(), and Window-Viewport Conversion.

### QPainter.setWindow (self, int x, int y, int w, int h)

This is an overloaded member function, provided for convenience.

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

### QPainter.setWorldMatrix (self, QMatrix matrix, bool combine = False)

Sets the transformation matrix to matrix and enables transformations.

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

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

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

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

- translate()
- scale()
- shear()
- rotate()

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

     void QPainter.rotate(qreal angle)
     {
         QMatrix matrix;
         matrix.rotate(angle);
         setWorldMatrix(matrix, true);
     }

Note that when using setWorldMatrix() 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 The Coordinate System documentation.

This function was introduced in Qt 4.2.

See also worldMatrixEnabled() and QMatrix.

### QPainter.setWorldMatrixEnabled (self, bool enabled)

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

This function was introduced in Qt 4.2.

See also worldMatrixEnabled(), worldMatrix(), and Coordinate Transformations.

### QPainter.setWorldTransform (self, QTransform matrix, bool 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.

See also worldTransform(), transform(), and setTransform().

### QPainter.shear (self, float sh, float sv)

Shears the coordinate system by (sh, sv).

See also setWorldMatrix() and Coordinate Transformations.

### QPainter.strokePath (self, QPainterPath path, QPen pen)

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

See also fillPath() and Drawing.

### bool QPainter.testRenderHint (self, RenderHint hint)

Returns true if hint is set; otherwise returns false.

This function was introduced in Qt 4.3.

See also renderHints() and setRenderHint().

### QTransform QPainter.transform (self)

Returns the world transformation matrix.

See also setTransform().

### QPainter.translate (self, QPointF offset)

Translates the coordinate system by the given offset; i.e. the given offset is added to points.

See also setWorldMatrix() and Coordinate Transformations.

### QPainter.translate (self, float dx, float dy)

This is an overloaded member function, provided for convenience.

Translates the coordinate system by the given offset.

### QPainter.translate (self, QPoint offset)

This is an overloaded member function, provided for convenience.

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

### QRect QPainter.viewport (self)

Returns the viewport rectangle.

See also setViewport() and setViewTransformEnabled().

### bool QPainter.viewTransformEnabled (self)

Returns true if view transformation is enabled; otherwise returns false.

See also setViewTransformEnabled() and worldMatrix().

### QRect QPainter.window (self)

Returns the window rectangle.

See also setWindow() and setViewTransformEnabled().

### QMatrix QPainter.worldMatrix (self)

Returns the world transformation matrix.

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

This function was introduced in Qt 4.2.

See also setWorldMatrix(), Coordinate Transformations, and The Coordinate System.

### bool QPainter.worldMatrixEnabled (self)

Returns true if world transformation is enabled; otherwise returns false.

This function was introduced in Qt 4.2.

See also setWorldMatrixEnabled(), worldMatrix(), and The Coordinate System.

### QTransform QPainter.worldTransform (self)

Returns the world transformation matrix.

See also setWorldTransform().