CopperSpice API  1.7.4
QPainter Class Reference

Performs low level painting operations on widgets and other paint devices. More...

Inheritance diagram for QPainter:

## Classes

class  PixmapFragment
A class used in conjunction with QPainter::drawPixmapFragments() to specify how a pixmap is drawn More...

## Public Typedefs

using PixmapFragmentHints = QFlags< PixmapFragmentHint >

using RenderHints = QFlags< RenderHint >

## Public Types

enum  CompositionMode

enum  PixmapFragmentHint

enum  RenderHint

## Public Methods

QPainter ()

QPainter (QPaintDevice *device)

~QPainter ()

const QBrushbackground () const

Qt::BGMode backgroundMode () const

bool begin (QPaintDevice *device)

void beginNativePainting ()

QRect boundingRect (const QRect &rect, int flags, const QString &text)

QRectF boundingRect (const QRectF &rect, const QString &text, const QTextOption &option=QTextOption ())

QRectF boundingRect (const QRectF &rect, int flags, const QString &text)

QRect boundingRect (int x, int y, int w, int h, int flags, const QString &text)

const QBrushbrush () const

QPoint brushOrigin () const

QRectF clipBoundingRect () const

QPainterPath clipPath () const

QRegion clipRegion () const

QMatrix combinedMatrix () const

QTransform combinedTransform () const

CompositionMode compositionMode () const

QPaintDevicedevice () const

const QMatrixdeviceMatrix () const

const QTransformdeviceTransform () const

void drawArc (const QRect &rect, int startAngle, int arcLength)

void drawArc (const QRectF &rect, int startAngle, int arcLength)

void drawArc (int x, int y, int w, int h, int startAngle, int arcLength)

void drawChord (const QRect &rect, int startAngle, int arcLength)

void drawChord (const QRectF &rect, int startAngle, int arcLength)

void drawChord (int x, int y, int w, int h, int startAngle, int arcLength)

void drawConvexPolygon (const QPoint *pointPtr, int pointCount)

void drawConvexPolygon (const QPointF *pointPtr, int pointCount)

void drawConvexPolygon (const QPolygon &polygon)

void drawConvexPolygon (const QPolygonF &polygon)

void drawEllipse (const QPoint &center, int rx, int ry)

void drawEllipse (const QPointF &center, qreal rx, qreal ry)

void drawEllipse (const QRect &rect)

void drawEllipse (const QRectF &rect)

void drawEllipse (int x, int y, int w, int h)

void drawGlyphRun (const QPointF &point, const QGlyphRun &glyphs)

void drawImage (const QPoint &point, const QImage &image)

void drawImage (const QPoint &point, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)

void drawImage (const QPointF &point, const QImage &image)

void drawImage (const QPointF &point, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)

void drawImage (const QRect &rect, const QImage &image)

void drawImage (const QRect &targetRect, const QImage &image, const QRect &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)

void drawImage (const QRectF &rect, const QImage &image)

void drawImage (const QRectF &targetRect, const QImage &image, const QRectF &sourceRect, Qt::ImageConversionFlags flags=Qt::AutoColor)

void drawImage (int x, int y, const QImage &image, int sx=0, int sy=0, int sw=-1, int sh=-1, Qt::ImageConversionFlags flags=Qt::AutoColor)

void drawLine (const QLine &line)

void drawLine (const QLineF &line)

void drawLine (const QPoint &p1, const QPoint &p2)

void drawLine (const QPointF &p1, const QPointF &p2)

void drawLine (int x1, int y1, int x2, int y2)

void drawLines (const QLine *linePtr, int lineCount)

void drawLines (const QLineF *linePtr, int lineCount)

void drawLines (const QPoint *pointPtr, int lineCount)

void drawLines (const QPointF *pointPtr, int lineCount)

void drawLines (const QVector< QLine > &lines)

void drawLines (const QVector< QLineF > &lines)

void drawLines (const QVector< QPoint > &points)

void drawLines (const QVector< QPointF > &points)

void drawPath (const QPainterPath &path)

void drawPicture (const QPoint &point, const QPicture &picture)

void drawPicture (const QPointF &point, const QPicture &picture)

void drawPicture (int x, int y, const QPicture &picture)

void drawPie (const QRect &rect, int startAngle, int arcLength)

void drawPie (const QRectF &rect, int startAngle, int arcLength)

void drawPie (int x, int y, int w, int h, int startAngle, int arcLength)

void drawPixmap (const QPoint &point, const QPixmap &pixmap)

void drawPixmap (const QPoint &point, const QPixmap &pixmap, const QRect &sourceRect)

void drawPixmap (const QPointF &point, const QPixmap &pixmap)

void drawPixmap (const QPointF &point, const QPixmap &pixmap, const QRectF &sourceRect)

void drawPixmap (const QRect &rect, const QPixmap &pixmap)

void drawPixmap (const QRect &targetRect, const QPixmap &pixmap, const QRect &sourceRect)

void drawPixmap (const QRectF &targetRect, const QPixmap &pixmap, const QRectF &sourceRect)

void drawPixmap (int x, int y, const QPixmap &pixmap)

void drawPixmap (int x, int y, const QPixmap &pixmap, int sx, int sy, int sw, int sh)

void drawPixmap (int x, int y, int w, int h, const QPixmap &pixmap)

void drawPixmap (int x, int y, int w, int h, const QPixmap &pixmap, int sx, int sy, int sw, int sh)

void drawPixmapFragments (const PixmapFragment *fragments, int fragmentCount, const QPixmap &pixmap, PixmapFragmentHints hints=PixmapFragmentHints ())

void drawPoint (const QPoint &point)

void drawPoint (const QPointF &point)

void drawPoint (int x, int y)

void drawPoints (const QPoint *pointPtr, int pointCount)

void drawPoints (const QPointF *pointPtr, int pointCount)

void drawPoints (const QPolygon &polygon)

void drawPoints (const QPolygonF &polygon)

void drawPolygon (const QPoint *pointPtr, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)

void drawPolygon (const QPointF *pointPtr, int pointCount, Qt::FillRule fillRule=Qt::OddEvenFill)

void drawPolygon (const QPolygon &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)

void drawPolygon (const QPolygonF &polygon, Qt::FillRule fillRule=Qt::OddEvenFill)

void drawPolyline (const QPoint *pointPtr, int pointCount)

void drawPolyline (const QPointF *pointPtr, int pointCount)

void drawPolyline (const QPolygon &polygon)

void drawPolyline (const QPolygonF &polygon)

void drawRect (const QRect &rect)

void drawRect (const QRectF &rect)

void drawRect (int x, int y, int w, int h)

void drawRects (const QRect *rectPtr, int rectCount)

void drawRects (const QRectF *rectPtr, int rectCount)

void drawRects (const QVector< QRect > &rectangles)

void drawRects (const QVector< QRectF > &rectangles)

void drawRoundedRect (int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)

void drawRoundRect (const QRect &rect, int xRound=25, int yRound=25)

void drawRoundRect (const QRectF &rect, int xRound=25, int yRound=25)

void drawRoundRect (int x, int y, int w, int h, int xRound=25, int yRound=25)

void drawStaticText (const QPoint &topLeftPosition, const QStaticText &staticText)

void drawStaticText (const QPointF &topLeftPosition, const QStaticText &staticText)

void drawStaticText (int left, int top, const QStaticText &staticText)

void drawText (const QPoint &point, const QString &text)

void drawText (const QPointF &point, const QString &text)

void drawText (const QRect &rect, int flags, const QString &text, QRect *boundingRect=nullptr)

void drawText (const QRectF &rect, const QString &text, const QTextOption &option=QTextOption ())

void drawText (const QRectF &rect, int flags, const QString &text, QRectF *boundingRect=nullptr)

void drawText (int x, int y, const QString &text)

void drawText (int x, int y, int w, int h, int flags, const QString &text, QRect *boundingRect=nullptr)

void drawTiledPixmap (const QRect &rect, const QPixmap &pixmap, const QPoint &point=QPoint ())

void drawTiledPixmap (const QRectF &rect, const QPixmap &pixmap, const QPointF &point=QPointF ())

void drawTiledPixmap (int x, int y, int w, int h, const QPixmap &pixmap, int sx=0, int sy=0)

bool end ()

void endNativePainting ()

void eraseRect (const QRect &rect)

void eraseRect (const QRectF &rect)

void eraseRect (int x, int y, int w, int h)

void fillPath (const QPainterPath &path, const QBrush &brush)

void fillRect (const QRect &rect, const QBrush &brush)

void fillRect (const QRect &rect, const QColor &color)

void fillRect (const QRect &rect, Qt::BrushStyle style)

void fillRect (const QRect &rect, Qt::GlobalColor color)

void fillRect (const QRectF &rect, const QBrush &brush)

void fillRect (const QRectF &rect, const QColor &color)

void fillRect (const QRectF &rect, Qt::BrushStyle style)

void fillRect (const QRectF &rect, Qt::GlobalColor color)

void fillRect (int x, int y, int w, int h, const QBrush &brush)

void fillRect (int x, int y, int w, int h, const QColor &color)

void fillRect (int x, int y, int w, int h, Qt::BrushStyle style)

void fillRect (int x, int y, int w, int h, Qt::GlobalColor color)

const QFontfont () const

QFontInfo fontInfo () const

QFontMetrics fontMetrics () const

bool hasClipping () const

void initFrom (const QPaintDevice *device)

bool isActive () const

Qt::LayoutDirection layoutDirection () const

const QMatrixmatrix () const

bool matrixEnabled () const

qreal opacity () const

QPaintEnginepaintEngine () const

const QPenpen () const

RenderHints renderHints () const

void resetMatrix ()

void resetTransform ()

void restore ()

void rotate (qreal angle)

void save ()

void scale (qreal sx, qreal sy)

void setBackground (const QBrush &brush)

void setBackgroundMode (Qt::BGMode mode)

void setBrush (const QBrush &brush)

void setBrush (Qt::BrushStyle style)

void setBrushOrigin (const QPoint &point)

void setBrushOrigin (const QPointF &point)

void setBrushOrigin (int x, int y)

void setClipPath (const QPainterPath &path, Qt::ClipOperation operation=Qt::ReplaceClip)

void setClipping (bool enable)

void setClipRect (const QRect &rect, Qt::ClipOperation operation=Qt::ReplaceClip)

void setClipRect (const QRectF &rect, Qt::ClipOperation operation=Qt::ReplaceClip)

void setClipRect (int x, int y, int w, int h, Qt::ClipOperation operation=Qt::ReplaceClip)

void setClipRegion (const QRegion &region, Qt::ClipOperation operation=Qt::ReplaceClip)

void setCompositionMode (CompositionMode mode)

void setFont (const QFont &font)

void setLayoutDirection (Qt::LayoutDirection direction)

void setMatrix (const QMatrix &matrix, bool combine=false)

void setMatrixEnabled (bool enable)

void setOpacity (qreal opacity)

void setPen (const QColor &color)

void setPen (const QPen &pen)

void setPen (Qt::PenStyle style)

void setRenderHint (RenderHint hint, bool on=true)

void setRenderHints (RenderHints hints, bool on=true)

void setTransform (const QTransform &transform, bool combine=false)

void setViewport (const QRect &viewport)

void setViewport (int x, int y, int w, int h)

void setViewTransformEnabled (bool enable)

void setWindow (const QRect &window)

void setWindow (int x, int y, int w, int h)

void setWorldMatrix (const QMatrix &matrix, bool combine=false)

void setWorldMatrixEnabled (bool enable)

void setWorldTransform (const QTransform &matrix, bool combine=false)

void shear (qreal sh, qreal sv)

void strokePath (const QPainterPath &path, const QPen &pen)

bool testRenderHint (RenderHint hint) const

const QTransformtransform () const

void translate (const QPoint &offset)

void translate (const QPointF &offset)

void translate (qreal dx, qreal dy)

QRect viewport () const

bool viewTransformEnabled () const

QRect window () const

const QMatrixworldMatrix () const

bool worldMatrixEnabled () const

const QTransformworldTransform () const

## Static Public Methods

static QPaintDeviceredirected (const QPaintDevice *device, QPoint *point=nullptr)

static void restoreRedirected (const QPaintDevice *device)

static void setRedirected (const QPaintDevice *device, QPaintDevice *replacement, const QPoint &point=QPoint ())

## Friends

class QPaintEngine

class QRasterPaintEngine

class QWidget

## Detailed Description

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

QPainter provides highly optimized methods to do many of the drawing operations required for a GUI program. The class 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 "native" coordinate system, but it can also draw using view and world transformations. QPainter can draw on any object which inherits the QPaintDevice class.

The following example shows how to create a custom widget using a QPainter object. This paintEvent() method will be called by the event system whenever the widget needs to be repainted.

void MyWidget::paintEvent(QPaintEvent *event) {
QPainter painter(this);
painter.setPen(Qt::blue);
painter.setFont(QFont("Arial", 30));
painter.drawText(rect(), Qt::AlignCenter, "CopperSpice");
}

### Paint System

The core functionality of QPainter is for drawing however the class also provides several methods that allow customizing QPainter settings. Some of the setting control rendering quality, enable clipping, or how different shapes can be merged together.

Using this class with the QPaintDevice and QPaintEngine classes forms the basis for the CopperSpice paint system. QPainter is the class used to perform drawing operations. QPaintDevice represents a device which can be painted on using a QPainter. QPaintEngine provides the interface the painter uses to draw on different types of devices.

The isActive() method indicates whether the painter is active. A painter is activated by the begin() method and the constructor that takes a QPaintDevice argument. The end() method and the destructor deactivates the painter. If the painter object is active then the device() method returns the paint device on which the painter paints and paintEngine() returns the paint engine that the painter is currently operating on.

### Settings

There are several settings which can be used to customize and make QPainter draw according to your preferences. Some of these settings mirror other settings in some paint devices, for example QWidget::font(). The QPainter::begin() method or the QPainter constructor copy these attributes from the paint device.

You can save the QPainter's state by calling the save() method which saves all the available settings on an internal stack. The restore() method pops them back.

font()
used for drawing text, when isActive() is true fontInfo() and fontMetrics() can be used to retrieve information about the currently set font
brush()
defines the color or pattern used for filling shapes
pen()
defines the color or stipple used for drawing lines or boundaries
backgroundMode()
defines if there is a background(), either Qt::OpaqueMode or Qt::TransparentMode
background()
only applies when backgroundMode() is Qt::OpaqueMode and pen() is a stipple, in that case this method describes the color of the background pixels in the stipple
brushOrigin()
defines the origin of the tiled brushes which is normally the origin of widget's background
viewport(), window(), worldTransform()
these make up the painter's coordinate transformation system, for more information refer to the Coordinate System and Coordinate Transformations
hasClipping()
indicates if the painter clips, if so it clips to clipRegion()
layoutDirection()
defines the layout direction used by the painter when drawing text
worldMatrixEnabled()
indicates if the world transformation is enabled
viewTransformEnabled()
indicates if the view transformation is enabled

### Drawing

QPainter provides methods to draw most primitives: drawPoint(), drawPoints(), drawLine(), drawRect(), drawRoundedRect(), drawEllipse(), drawArc(), drawPie(), drawChord(), drawPolyline(), drawPolygon(), drawConvexPolygon(), and drawCubicBezier(). The convenience methods drawRects() and drawLines() draw the given number of rectangles or lines in the given array of QRect or QLine using the current pen and brush.

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

All of these methods have both integer and floating point versions. 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(). The QPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused.

QPainter also provides the fillPath() method which fills the given QPainterPath with the given QBrush, and the strokePath() method that draws the outline of the given path. There are methods 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.

### Drawing Pixmaps and Images

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

The drawPicture() method draws the contents of an entire QPicture. The drawPicture() method is the only one which disregards all the painter's settings as QPicture has its own settings.

### High Resolution Pixmaps and Images

High resolution versions of pixmaps have a device pixel ratio value larger than 1.

If the pixel ratio matches the value of the underlying QPaintDevice, the pixmap is drawn directly with no additional transformation applied. This occurs 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. The pixmap is then effectively 32x32 pixels in user coordinates. Code paths in CopperSpice 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.

### Rendering Quality

To obtain a consistent rendering result using QPainter specify a QImage for the paint device. 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 methods for drawing primitives have a floating point version. These are often used in combination with the QPainter::Antialiasing render hint.

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.

The renderHints() method returns a flag which specifies the current rendering hints for this painter. Use the setRenderHint() method to change the RenderHints.

### Coordinate Transformations

Normally, the QPainter operates on a device native coordinate system (usually pixels). However, QPainter does support coordinate transformations.

originalrotate()scale()translate()

The most commonly used transformations are scaling, rotation, translation and shearing. Use the scale() method to scale the coordinate system by a given offset, the rotate() method to rotate it clockwise and translate() to translate it. You can also twist the coordinate system around the origin using the shear() method.

All the transformation operations operate on the transformation worldTransform(). A matrix transforms a point in the plane to another point.

The setWorldTransform() function can replace or add to the currently set worldTransform(). The 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 natively.

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

Coordinate System

### 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 the QPainter does 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.

Composition transformations operate on each pixel. For this reason, there is a difference between using the graphic primitive itself and its bounding rectangle. The bounding rectangle 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.

### Limitations

When using coordinates with the CopperSpice raster-based paint engine anything outside the range of +/- 215 is not guaranteed to be shown and the drawing may be clipped.

The outlines generated by the stroker are only an approximation for curved shapes. It is typically not possible to represent the bezier curve segment using another bezier curve segment, so CopperSpice approximates the curve outlines. For performance reasons there is a limit to how many curves are used. When using large pen widths or scales the outline error increases. To generate outlines with smaller errors use the QPainterPathStroker class and call the setCurveThreshold method to specify the error tolerance. Another option is to convert the paths to polygons first and then draw the polygons instead.

### Performance

QPainter allows developers to do a variety of graphical operations, such as gradients, composition modes and vector graphics. These operations are supported on a variety of different hardware and software stacks.The underlying combination of hardware and software has some implications for performance. Optimizing every combination of operations is not practical.

The backends we focus on as high-performance engines are the following two.

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 QImage::Format_ARGB32_Premultiplied, QImage::Format_RGB32 or QImage::Format_RGB16. Any other format, including QImage::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.

The high performance operations are listed below.

• Simple transformations, meaning translation and scaling, plus 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.
• Composition Modes QPainter::CompositionMode_Source and QPainter::CompositionMode_SourceOver
• Rounded rectangle filling using solid color and two-color linear gradients fills.
• 3x3 patched pixmaps, via qDrawBorderPixmap.
QPaintDevice, QPaintEngine, CsSvg library, Drawing Utility Functions

## Member Typedef Documentation

Typedef for QFlags<PixmapFragmentHint>. Refer to QPainter::PixmapFragmentHint for documentation.

Typedef for QFlags<RenderHint>. Refer to QPainter::RenderHints for documentation.

## Member Enumeration Documentation

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 QPainter::Antialiasing render hint will effectively disable the RasterOp modes.

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.

ConstantValueDescription
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 15Multiplies 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_Darken16The darker of the source and destination colors is selected.
QPainter::CompositionMode_Lighten17 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 19The 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 21Darkens 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.
QPainter::RasterOp_SourceOrDestination 24 Does a bitwise OR operation on the source and destination pixels (src OR dst).
QPainter::RasterOp_SourceAndDestination 25 Does a bitwise AND operation on the source and destination pixels (src AND dst).
QPainter::RasterOp_SourceXorDestination 26Does a bitwise XOR operation on the source and destination pixels (src XOR dst).
QPainter::RasterOp_NotSourceAndNotDestination27 Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)).
QPainter::RasterOp_NotSourceOrNotDestination 28Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT dst)).
QPainter::RasterOp_NotSourceXorDestination29 Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst).
QPainter::RasterOp_NotSourceXorDestination 29 Does a bitwise operation where the source pixels are inverted and then XOR'ed with the destination ((NOT src) XOR dst).
QPainter::RasterOp_NotSource 30 Does a bitwise operation where the source pixels are inverted (NOT src).
QPainter::RasterOp_NotSourceAndDestination 31 Does a bitwise operation where the source is inverted and then AND'ed with the destination ((NOT src) AND dst).
QPainter::RasterOp_SourceAndNotDestination 32 Does a bitwise operation where the source is AND'ed with the inverted destination pixels (src AND (NOT dst)).
QPainter::RasterOp_NotSourceOrDestination 33 Does a bitwise operation where the source is inverted and then OR'ed with the destination ((NOT src) OR dst).
QPainter::RasterOp_SourceOrNotDestination 34 Does a bitwise operation where the source is OR'ed with the inverted destination pixels (src OR (NOT dst)).
QPainter::RasterOp_ClearDestination 35 Pixels in the destination are cleared (set to 0) independent of the source.
QPainter::RasterOp_SetDestination 36 Pixels in the destination are set (set to 1) independent of the source.
QPainter::RasterOp_NotDestination 37 Does a bitwise operation where the destination pixels are inverted (NOT dst).
compositionMode(), setCompositionMode()
ConstantValueDescription
QPainter::OpaqueHint0x01 Indicates that the pixmap fragments to be drawn are opaque. Opaque fragments are potentially faster to draw.
QPainter::drawPixmapFragments(), QPainter::PixmapFragment
 enum QPainter::RenderHint

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

ConstantValueDescription
QPainter::Antialiasing0x01 Indicates that the engine should antialias edges of primitives if possible.
QPainter::TextAntialiasing0x02 Indicates that the engine should antialias text if possible. To forcibly disable antialiasing for text, do not use this hint. Instead, set QFont::NoAntialias on your font's style strategy.
QPainter::SmoothPixmapTransform0x04 Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor.
QPainter::HighQualityAntialiasing0x08 An OpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.
QPainter::NonCosmeticDefaultPen0x10 The engine should interpret pens with a width of 0 (which otherwise enables QPen::isCosmetic()) as being a non-cosmetic pen with a width of 1.
renderHints(), setRenderHint()

## Constructor & Destructor Documentation

 QPainter::QPainter ( )

Constructs a painter.

begin(), end()
 QPainter::QPainter ( QPaintDevice * device )
explicit

Constructs a painter which begins painting the device immediately. Calls begin() and the destructor automatically calls end(). This constructor is convenient for short lived painters like QWidget::paintEvent() and should be used only once.

The following is an example using the begin() and end() methods. Since the constructor does not provide feedback if the initialization fails, it is usually better to use begin() and end() to paint on external devices.

void MyWidget::paintEvent(QPaintEvent *) {
p.begin(this);
p.drawLine(...);
p.end();
}

This code produces the same result using this constructor.

void MyWidget::paintEvent(QPaintEvent *)
{
QPainter p(this);
p.drawLine(...);
}
begin(), end()
 QPainter::~QPainter ( )

Destroys the QPainter.

## Method Documentation

 const QBrush & QPainter::background ( ) const

Returns the current background brush.

setBackground()
 Qt::BGMode QPainter::backgroundMode ( ) const

Returns the current background mode.

setBackgroundMode()
 bool QPainter::begin ( QPaintDevice * device )

Begins painting the paint device and returns true if successful, otherwise returns false. All painter settings such as setPen() and setBrush() are reset to default values when begin() is called. A paint device can only be painted by one painter at a time.

The following code shows some of the errors which can occur.

painter->begin(nullptr); // paint device can not be a nullptr (error)
QPixmap image(0, 0);
painter->begin(&image); // image can not be NULL (error)
painter->begin(myWidget);
painter2->begin(myWidget); // only one painter object can be drawing at a time (error)
Warning
Painting on a QImage with the format QImage::Format_Indexed8 is not supported.
end(), QPainter()
 void 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().

Only the states the underlying paint engine changes will be reset to their respective default states. The states reseted may change in a new release of CopperSpice. The following states are currently reset in the OpenGL 2 engine.

• blending is disabled
• depth, stencil and scissor tests are disabled
• active texture unit is reset to 0
• depth mask, depth function and the clear depth are reset to their default values
• stencil mask, stencil operation and stencil function are reset to their default values
• 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:

QPainter painter(this);
painter.fillRect(0, 0, 128, 128, Qt::green);
glEnable(GL_SCISSOR_TEST);
glScissor(0, 0, 64, 64);
glClearColor(1, 0, 0, 1);
glClear(GL_COLOR_BUFFER_BIT);
glDisable(GL_SCISSOR_TEST);
endNativePainting()
 QRect QPainter::boundingRect ( const QRect & rect, int flags, const QString & text )

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

 QRectF QPainter::boundingRect ( const QRectF & rect, const QString & text, const QTextOption & option = QTextOption() )

Instead of specifying flags as a bitwise OR of the Qt::AlignmentFlag and Qt::TextFlag, this method takes an option argument. The QTextOption class provides a description of rich text properties.

QTextOption
 QRectF QPainter::boundingRect ( const QRectF & rect, int flags, const QString & text )

Returns the bounding rectangle of the text as it will appear when drawn inside the given rect with the specified flags using the currently set font(). This method indicates where the drawText() method will draw when given the same arguments. If the text does not fit within the given rectangle using the specified flags, the method returns the required rectangle.

The flags argument is a bitwise OR of the following flags. If several of the horizontal or several of the vertical alignment flags are set, the resulting alignment is undefined.

• Qt::AlignLeft
• Qt::AlignRight
• Qt::AlignHCenter
• Qt::AlignTop
• Qt::AlignBottom
• Qt::AlignVCenter
• Qt::AlignCenter
• Qt::TextSingleLine
• Qt::TextExpandTabs
• Qt::TextShowMnemonic
• Qt::TextWordWrap
• Qt::TextIncludeTrailingSpaces
drawText(), Qt::Alignment, Qt::TextFlag
 QRect QPainter::boundingRect ( int x, int y, int w, int h, int flags, const QString & text )
inline

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 and height.

 const QBrush & QPainter::brush ( ) const

Returns the painter's current brush.

QPainter::setBrush()
 QPoint QPainter::brushOrigin ( ) const

Returns the currently set brush origin.

setBrushOrigin()
 QRectF QPainter::clipBoundingRect ( ) const

Returns the bounding rectangle of the current clip if there is a clip, otherwise returns an empty rectangle. The clip region is given in logical coordinates. The bounding rectangle is not guaranteed to be tight.

setClipRect(), setClipPath(), setClipRegion()
 QPainterPath QPainter::clipPath ( ) const

Returns the current clip as a path. The clip path 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.

setClipPath(), clipRegion(), setClipping()
 QRegion QPainter::clipRegion ( ) const

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.

setClipRegion(), clipPath(), setClipping()
 QMatrix QPainter::combinedMatrix ( ) const
deprecated
Deprecated:
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.

setWorldTransform(), setWindow(), setViewport()
 QTransform QPainter::combinedTransform ( ) const

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

setWorldTransform(), setWindow(), setViewport()
 CompositionMode QPainter::compositionMode ( ) const

Returns the current composition mode.

CompositionMode, setCompositionMode()
 QPaintDevice * QPainter::device ( ) const

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

isActive()
 const QMatrix & QPainter::deviceMatrix ( ) const
deprecated
Deprecated:
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.

You should use deviceTransform() instead of this method to preserve the properties of perspective transformations. This method is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations natively. The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

worldMatrix(), QPaintEngine::hasFeature()
 const QTransform & QPainter::deviceTransform ( ) const

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

This methods is only needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations natively. The QPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.

worldTransform(), QPaintEngine::hasFeature()
 void QPainter::drawArc ( const QRect & rect, int startAngle, int arcLength )
inline

Draws the arc defined by the given rect, startAngle, and arcLength.

 void QPainter::drawArc ( const QRectF & rect, int startAngle, int arcLength )

Draws the arc defined by the given rect, startAngle, and arcLength.

The startAngle and spanAngle must be specified in 1/16th of a degree. For example, 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 arcLength = 120 * 16; QPainter painter(this); painter.drawArc(rectangle, startAngle, arcLength);
drawPie(), drawChord(), Coordinate System
 void QPainter::drawArc ( int x, int y, int w, int h, int startAngle, int arcLength )
inline

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

 void QPainter::drawChord ( const QRect & rect, int startAngle, int arcLength )
inline

Draws the chord defined by the given rect, startAngle, and arcLength.

 void QPainter::drawChord ( const QRectF & rect, int startAngle, int arcLength )

Draws the chord defined by the given rect, startAngle and arcLength. The chord is filled with the current brush(). The startAngle and arcLength must be specified in 1/16th of a degree. For example 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 arcLength = 120 * 16; QPainter painter(this); painter.drawChord(rect, startAngle, arcLength);
drawArc(), drawPie(), Coordinate System
 void QPainter::drawChord ( int x, int y, int w, int h, int startAngle, int arcLength )
inline

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

 void QPainter::drawConvexPolygon ( const QPoint * pointPtr, int pointCount )

Draws a convex polygon defined by points starting at pointPtr for the given number of points specified in pointCount using the current pen.

 void QPainter::drawConvexPolygon ( const QPointF * pointPtr, int pointCount )

Draws a convex polygon defined by points starting at pointPtr for the given number of points specified in pointCount using the current pen.

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, which means it contains at least one angle larger than 180 degrees, the results are undefined.

On some platforms such as X11 drawConvexPolygon() can be faster than using drawPolygon().

 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);
drawPolygon(), drawPolyline(), Coordinate System
 void QPainter::drawConvexPolygon ( const QPolygon & polygon )
inline

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

 void QPainter::drawConvexPolygon ( const QPolygonF & polygon )
inline

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

 void QPainter::drawEllipse ( const QPoint & center, int rx, int ry )
inline

Draws the ellipse positioned at thegiven center point. The values for rx and ry specify the distance for each axis.

 void QPainter::drawEllipse ( const QPointF & center, qreal rx, qreal ry )
inline

Draws the ellipse positioned at thegiven center point. The values for rx and ry specify the distance for each axis.

 void QPainter::drawEllipse ( const QRect & rect )

Draws the ellipse defined by the given rect.

 void QPainter::drawEllipse ( const QRectF & rect )

Draws the ellipse defined by the given rect. 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);
drawPie(), Coordinate System
 void QPainter::drawEllipse ( int x, int y, int w, int h )
inline

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

 void QPainter::drawGlyphRun ( const QPointF & point, const QGlyphRun & glyphs )

Draws the specified glyphs at the given point. The position gives the edge of the baseline for the string of glyphs. The glyphs will be retrieved from the font selected by glyphs and at offsets given by the positions in glyphs.

QGlyphRun::setRawFont(), QGlyphRun::setPositions(), QGlyphRun::setGlyphIndexes()
 void QPainter::drawImage ( const QPoint & point, const QImage & image )
inline

Draws the given image at the given point.

 void QPainter::drawImage ( const QPoint & point, const QImage & image, const QRect & sourceRect, Qt::ImageConversionFlags flags = Qt::AutoColor )
inline

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

 void QPainter::drawImage ( const QPointF & point, const QImage & image )

Draws the given image at the given point.

 void QPainter::drawImage ( const QPointF & point, const QImage & image, const QRectF & sourceRect, Qt::ImageConversionFlags flags = Qt::AutoColor )
inline

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

 void QPainter::drawImage ( const QRect & rect, const QImage & image )
inline

Draws the given image into the given rect. The image is scaled to fit the rectangle, if the image and rectangle size do not match.

 void QPainter::drawImage ( const QRect & targetRect, const QImage & image, const QRect & sourceRect, Qt::ImageConversionFlags flags = Qt::AutoColor )
inline

Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

 void QPainter::drawImage ( const QRectF & rect, const QImage & image )
inline

Draws the given image into the given rect. The image is scaled to fit the rectangle, if the image and rectangle size do not match.

 void QPainter::drawImage ( const QRectF & targetRect, const QImage & image, const QRectF & sourceRect, Qt::ImageConversionFlags flags = Qt::AutoColor )

Draws the rectangular portion sourceRect of the given image into the targetRect rectangle in the paint device. The image is scaled to fit the rectangle, if both the image and rectangle size disagree.

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 painter(this);
painter.drawImage(target, image, source);
drawPixmap()
 void QPainter::drawImage ( int x, int y, const QImage & image, int sx = 0, int sy = 0, int sw = -1, int sh = -1, Qt::ImageConversionFlags flags = Qt::AutoColor )
inline

Draws an image at (x, y) by copying a part of image into the paint device. The values for x and y specify the top-left point in the paint device that is to be drawn onto.

The values for (sx, sy) specify the top-left point in image that is to be drawn. The default is (0, 0).

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

 void QPainter::drawLine ( const QLine & line )
inline

Draws a line defined by line.

 void QPainter::drawLine ( const QLineF & line )
inline

Draws a line defined by line.

 QLineF line(10.0, 80.0, 90.0, 20.0); QPainter(this); painter.drawLine(line);
drawLines(), drawPolyline(), Coordinate System
 void QPainter::drawLine ( const QPoint & p1, const QPoint & p2 )
inline

Draws a line from point1 to point2.

 void QPainter::drawLine ( const QPointF & p1, const QPointF & p2 )
inline

Draws a line from point1 to point2.

 void QPainter::drawLine ( int x1, int y1, int x2, int y2 )
inline

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

 void QPainter::drawLines ( const QLine * linePtr, int lineCount )

Draws a list of lines starting at linePtr for the given number of lines, specified in lineCount using the current pen.

 void QPainter::drawLines ( const QLineF * linePtr, int lineCount )

Draws a list of lines starting at linePtr for the given number of lines, specified in lineCount using the current pen.

drawLine(), drawPolyline()
 void QPainter::drawLines ( const QPoint * pointPtr, int lineCount )

Draws the list of lines starting at pointPtr for the given number of lines, specified in lineCount using the current pen. The lines are specified as pairs of points so the number of entries in linePtr must be at least lineCount * 2.

 void QPainter::drawLines ( const QPointF * pointPtr, int lineCount )

Draws the list of lines starting at pointPtr for the given number of lines, specified in lineCount using the current pen. The lines are specified as pairs of points so the number of entries in linePtr must be at least lineCount * 2.

 void QPainter::drawLines ( const QVector< QLine > & lines )
inline

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

 void QPainter::drawLines ( const QVector< QLineF > & lines )
inline

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

 void QPainter::drawLines ( const QVector< QPoint > & points )
inline

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

 void QPainter::drawLines ( const QVector< QPointF > & points )
inline

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

 void QPainter::drawPath ( const 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);
 void QPainter::drawPicture ( const QPoint & point, const QPicture & picture )
inline

Replays the given picture at the given point.

 void QPainter::drawPicture ( const QPointF & point, const 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)
QPainter painter(this);
painter.drawPicture(0, 0, picture);
QPicture::play()
 void QPainter::drawPicture ( int x, int y, const QPicture & picture )
inline

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

 void QPainter::drawPie ( const QRect & rect, int startAngle, int arcLength )
inline

Draws a pie defined by the given rect, startAngle, and arcLength.

 void QPainter::drawPie ( const QRectF & rect, int startAngle, int arcLength )

Draws a pie defined by the given rect, startAngle, and arcLength. The pie is filled with the current brush().

The startAngle and arcLength must be specified in 1/16th of a degree. For example 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 arcLength = 120 * 16; QPainter painter(this); painter.drawPie(rectangle, startAngle, arcLength);
drawEllipse(), drawChord(), Coordinate System
 void QPainter::drawPie ( int x, int y, int w, int h, int startAngle, int arcLength )
inline

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

 void QPainter::drawPixmap ( const QPoint & point, const QPixmap & pixmap )
inline

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

 void QPainter::drawPixmap ( const QPoint & point, const QPixmap & pixmap, const QRect & sourceRect )
inline

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

 void QPainter::drawPixmap ( const QPointF & point, const QPixmap & pixmap )

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

 void QPainter::drawPixmap ( const QPointF & point, const QPixmap & pixmap, const QRectF & sourceRect )
inline

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

 void QPainter::drawPixmap ( const QRect & rect, const QPixmap & pixmap )
inline

Draws the given pixmap into the given rect. The pixmap is scaled to fit the rectangle, if the pixmap and rectangle size do not match.

 void QPainter::drawPixmap ( const QRect & targetRect, const QPixmap & pixmap, const QRect & sourceRect )
inline

Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device. The pixmap is scaled to fit the rectangle, if the pixmap and rectangle size do not match.

 void QPainter::drawPixmap ( const QRectF & targetRect, const QPixmap & pixmap, const QRectF & sourceRect )

Draws the rectangular portion sourceRect of the given pixmap into the given targetRect in the paint device. The pixmap is scaled to fit the rectangle, if the pixmap and rectangle size do not match.

If pixmap is a QBitmap it is drawn with the bits that are "set" using the pen 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.

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);
drawImage()
 void QPainter::drawPixmap ( int x, int y, const QPixmap & pixmap )
inline

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

 void QPainter::drawPixmap ( int x, int y, const QPixmap & pixmap, int sx, int sy, int sw, int sh )
inline

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

The X and Y coordinates specify the top-left point in the paint device. The SX and SY coordinates specify the top-left point in the pixmap. The SW and SH coordinates specify the size of the pixmap.

 void QPainter::drawPixmap ( int x, int y, int w, int h, const QPixmap & pixmap )
inline

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

 void QPainter::drawPixmap ( int x, int y, int w, int h, const QPixmap & pixmap, int sx, int sy, int sw, int sh )
inline

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.

 void QPainter::drawPixmapFragments ( const PixmapFragment * fragments, int fragmentCount, const QPixmap & pixmap, PixmapFragmentHints hints = PixmapFragmentHints() )

Draws pixmap, or a sub-rectangle of pixmap, at multiple positions with different scale, rotation, and opacity. The value for 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 method is potentially faster than multiple calls to drawPixmap() since the backend can optimize state changes.

QPainter::PixmapFragmentHint
 void QPainter::drawPoint ( const QPoint & point )
inline

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

 void QPainter::drawPoint ( const QPointF & point )
inline

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

Coordinate System
 void QPainter::drawPoint ( int x, int y )
inline

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

 void QPainter::drawPoints ( const QPoint * pointPtr, int pointCount )

Draws points starting from pointPtr for the given number of points specified in pointCount.

 void QPainter::drawPoints ( const QPointF * pointPtr, int pointCount )

Draws points starting from pointPtr for the given number of points specified in pointCount.

Coordinate System
 void QPainter::drawPoints ( const QPolygon & polygon )
inline

Draws the points in the vector point.

 void QPainter::drawPoints ( const QPolygonF & polygon )
inline

Draws the points in the vector point.

 void QPainter::drawPolygon ( const QPoint * pointPtr, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill )

Draws a polygon defined by points starting at pointPtr for the given number of points specified in pointCount using the given fillRule.

 void QPainter::drawPolygon ( const QPointF * pointPtr, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill )

Draws a polygon defined by points starting at pointPtr for the given number of points specified in pointCount using the current pen and brush. 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. Refer to Qt::FillRule for a detailed description of these fill rules.

 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);
drawConvexPolygon(), drawPolyline(), Coordinate System
 void QPainter::drawPolygon ( const QPolygon & polygon, Qt::FillRule fillRule = Qt::OddEvenFill )
inline

Draws the polygon defined by the given point using the given fillRule.

 void QPainter::drawPolygon ( const QPolygonF & polygon, Qt::FillRule fillRule = Qt::OddEvenFill )
inline

Draws the polygon defined by the given point using the given fillRule.

 void QPainter::drawPolyline ( const QPoint * pointPtr, int pointCount )

Draws the polyline defined by points starting at pointPtr for the given number of points specified in pointCount using the current pen.

 void QPainter::drawPolyline ( const QPointF * pointPtr, int pointCount )

Draws the polyline defined by points starting at pointPtr for the given number of points specified in pointCount using the current pen. 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);
drawLines(), drawPolygon(), Coordinate System
 void QPainter::drawPolyline ( const QPolygon & polygon )
inline

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

 void QPainter::drawPolyline ( const QPolygonF & polygon )
inline

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

 void QPainter::drawRect ( const QRect & rect )
inline

Draws the given rect with the current pen and brush.

 void QPainter::drawRect ( const QRectF & rect )
inline

Draws the given rect with the current pen and brush. A filled rectangle has a size of rect.size(). A stroked rectangle has a size of rect.size() plus the pen width.

 QRectF rectangle(10.0, 20.0, 80.0, 60.0); QPainter painter(this); painter.drawRect(rectangle);
drawRects(), drawPolygon(), Coordinate System
 void QPainter::drawRect ( int x, int y, int w, int h )
inline

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

 void QPainter::drawRects ( const QRect * rectPtr, int rectCount )

Draws rectangles starting from rectPtr for the given number of rectangles specified in rectCount using the current pen and brush.

 void QPainter::drawRects ( const QRectF * rectPtr, int rectCount )

Draws rectangles starting from rectPtr for the given number of rectangles specified in rectCount using the current pen and brush.

drawRect()
 void QPainter::drawRects ( const QVector< QRect > & rectangles )
inline

Draws the given rectangles using the current pen and brush.

 void QPainter::drawRects ( const QVector< QRectF > & rectangles )
inline

Draws the given rectangles using the current pen and brush.

 void QPainter::drawRoundedRect ( const QRect & rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize )
inline

Draws the given rect with rounded corners.

The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize then xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively and should be in the range 0.0 to 100.0.

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

 void QPainter::drawRoundedRect ( const QRectF & rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize )

Draws the given rect with rounded corners.

The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize then xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively and should be in the range 0.0 to 100.0.

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

 QRectF rectangle(10.0, 20.0, 80.0, 60.0); QPainter painter(this); painter.drawRoundedRect(rectangle, 20.0, 15.0);
drawRect(), QPen
 void QPainter::drawRoundedRect ( int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize )
inline

Draws a rectangle using x, y, width, height with rounded corners.

The xRadius and yRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. When mode is Qt::RelativeSize then xRadius and yRadius are specified in percentage of half the rectangle's width and height respectively and should be in the range 0.0 to 100.0.

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

 void QPainter::drawRoundRect ( const QRect & rect, int xRound = 25, int yRound = 25 )
inlinedeprecated
Deprecated:
Draws the given rect with rounded corners.
drawRoundedRect()
 void QPainter::drawRoundRect ( const QRectF & rect, int xRound = 25, int yRound = 25 )
deprecated
Deprecated:
Draws the given rect with rounded corners.

The xRound and yRound arguments specify how rounded the corners should be. 0 is angled corners, 99 is maximum roundedness. A filled rectangle has a size of rectangle.size(). A stroked rectangle has a size of rectangle.size() plus the pen width.

drawRoundedRect()
 void QPainter::drawRoundRect ( int x, int y, int w, int h, int xRound = 25, int yRound = 25 )
inlinedeprecated
Deprecated:
Draws the rectangle x, y, w, h with rounded corners.
drawRoundedRect()
 void QPainter::drawStaticText ( const QPoint & topLeftPosition, const QStaticText & staticText )
inline

Draws the staticText at the topLeftPosition.

If the painter's transformation is not affine then staticText will be drawn using regular calls to drawText(). The y-position is used as the top of the font.

 void QPainter::drawStaticText ( const QPointF & topLeftPosition, const QStaticText & staticText )

Draws the given staticText at the given topLeftPosition.

The text will be drawn using the font and the transformation set on the painter. If the font and/or transformation set on the painter are different from the ones used to initialize the layout of the QStaticText, then the layout will have to be recalculated. Use QStaticText::prepare() to initialize staticText with the font and transformation with which it will later be drawn.

If topLeftPosition is not the same as when staticText was initialized, or when it was last drawn, then there will be a slight overhead when translating the text to its new position.

If the painter's transformation is not affine then staticText will be drawn using regular calls to drawText(). The y-position is used as the top of the font.

QStaticText
 void QPainter::drawStaticText ( int left, int top, const QStaticText & staticText )
inline

Draws the staticText at coordinates left and top.

If the painter's transformation is not affine then staticText will be drawn using regular calls to drawText(). The y-position is used as the top of the font.

 void QPainter::drawText ( const QPoint & point, const QString & text )
inline

Draws the given text with the currently defined text direction, beginning at the given point. By default, QPainter draws text anti-aliased.

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

 void QPainter::drawText ( const QPointF & point, const QString & text )

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

This function does not handle the newline character (\n), as it can not break text into multiple lines, and it can not 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.

By default QPainter draws text anti-aliased. The y-position is used as the baseline of the font.

 void QPainter::drawText ( const QRect & rect, int flags, const QString & text, QRect * boundingRect = nullptr )

Draws the given text within the provided rect according to the specified flags. The boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text.

By default QPainter draws text anti-aliased. The y-coordinate of the rectangle is used as the top of the font.

 void QPainter::drawText ( const QRectF & rect, const QString & text, const QTextOption & option = QTextOption() )

Draws the given text in the rect specified using the option to control its positioning and orientation.

By default QPainter draws text anti-aliased. The y-coordinate of rectangle is used as the top of the font.

 void QPainter::drawText ( const QRectF & rect, int flags, const QString & text, QRectF * boundingRect = nullptr )

Draws the given text within the provided rect.

 QPainter painter(this); painter.drawText(rect, Qt::AlignCenter, tr("CopperSpice\nProject"));

The boundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text. The flags argument is a bitwise OR of the following flags.

• Qt::AlignLeft
• Qt::AlignRight
• Qt::AlignHCenter
• Qt::AlignJustify
• Qt::AlignTop
• Qt::AlignBottom
• Qt::AlignVCenter
• Qt::AlignCenter
• Qt::TextDontClip
• Qt::TextSingleLine
• Qt::TextExpandTabs
• Qt::TextShowMnemonic
• Qt::TextWordWrap
• Qt::TextIncludeTrailingSpaces

By default QPainter draws text anti-aliased. The y-coordinate of the rectangle is used as the top of the font.

Qt::AlignmentFlag, Qt::TextFlag, boundingRect(), layoutDirection()
 void QPainter::drawText ( int x, int y, const QString & text )
inline

Draws the given text at position (x, y), using the painter's currently defined text direction.

By default, QPainter draws text anti-aliased. The y-position is used as the baseline of the font.

 void QPainter::drawText ( int x, int y, int w, int h, int flags, const QString & text, QRect * boundingRect = nullptr )
inline

Draws the given text within the rectangle with origin (x, y), width and height. The boundingRect (if not null) is set to the actual bounding rectangle of the output. The flags argument is a bitwise OR of the following flags.

• Qt::AlignLeft
• Qt::AlignRight
• Qt::AlignHCenter
• Qt::AlignJustify
• Qt::AlignTop
• Qt::AlignBottom
• Qt::AlignVCenter
• Qt::AlignCenter
• Qt::TextSingleLine
• Qt::TextExpandTabs
• Qt::TextShowMnemonic
• Qt::TextWordWrap

By default, QPainter draws text anti-aliased. The y-position is used as the top of the font.

Qt::AlignmentFlag, Qt::TextFlag
 void QPainter::drawTiledPixmap ( const QRect & rect, const QPixmap & pixmap, const QPoint & point = QPoint() )
inline

Draws a tiled pixmap inside the given rect with its origin at the given point.

 void QPainter::drawTiledPixmap ( const QRectF & rect, const QPixmap & pixmap, const QPointF & point = QPointF() )

Draws a tiled pixmap inside the given rect with its origin at the given point.

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.

drawPixmap()
 void QPainter::drawTiledPixmap ( int x, int y, int w, int h, const QPixmap & pixmap, int sx = 0, int sy = 0 )
inline

Draws a tiled pixmap in the specified rectangle.

The (x, y) coordinates specify the top-left point in the paint device. The size is specified by the width and height. The (sx, sy) coordinates specify the top-left point in the given pixmap.

 bool QPainter::end ( )

Ends the painting process. Any resources used while painting are released. You do not normally need to call this since it is called by the destructor. Returns true if the painter is no longer active, otherwise returns false.

begin(), isActive()
 void 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.

beginNativePainting()
 void QPainter::eraseRect ( const QRect & rect )
inline

Erases the area inside the given rect.

 void QPainter::eraseRect ( const QRectF & rect )

Erases the area inside the given rect. Equivalent to calling fillRect(rectangle, background())

fillRect()
 void QPainter::eraseRect ( int x, int y, int w, int h )
inline

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

 void QPainter::fillPath ( const QPainterPath & path, const QBrush & brush )

Fills the given path using the brush. The outline is not drawn. Alternatively, you can specify a QColor instead of a QBrush. The QBrush constructor will automatically create a solid pattern brush.

drawPath()
 void QPainter::fillRect ( const QRect & rect, const QBrush & brush )

Fills the given rect with the specified brush.

 void QPainter::fillRect ( const QRect & rect, const QColor & color )

Fills the given rect with the specified color.

 void QPainter::fillRect ( const QRect & rect, Qt::BrushStyle style )
inline

Fills the given rect with the brush style specified.

 void QPainter::fillRect ( const QRect & rect, Qt::GlobalColor color )
inline

Fills the given rect with the specified color.

 void QPainter::fillRect ( const QRectF & rect, const QBrush & brush )

Fills the given rect using the brush. Alternatively, you can specify a QColor instead of a QBrush. The QBrush constructor will automatically create a solid pattern brush.

drawRect()
 void QPainter::fillRect ( const QRectF & rect, const QColor & color )

Fills the given rect with the specified color.

 void QPainter::fillRect ( const QRectF & rect, Qt::BrushStyle style )
inline

Fills the given rect with the brush specified style.

 void QPainter::fillRect ( const QRectF & rect, Qt::GlobalColor color )
inline

Fills the given rect with the specified color.

 void QPainter::fillRect ( int x, int y, int w, int h, const QBrush & brush )
inline

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

 void QPainter::fillRect ( int x, int y, int w, int h, const QColor & color )
inline

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

 void QPainter::fillRect ( int x, int y, int w, int h, Qt::BrushStyle style )
inline

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

 void QPainter::fillRect ( int x, int y, int w, int h, Qt::GlobalColor color )
inline

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

 const QFont & QPainter::font ( ) const

Returns the currently set font used for drawing text.

setFont(), drawText()
 QFontInfo QPainter::fontInfo ( ) const

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

font(), isActive()
 QFontMetrics QPainter::fontMetrics ( ) const

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

font(), isActive()
 bool QPainter::hasClipping ( ) const

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

setClipping()
 void QPainter::initFrom ( const QPaintDevice * device )

Initializes the painters pen, background and font to the same as the given device. This method is called automatically when the painter is opened on a QWidget.

begin()
 bool QPainter::isActive ( ) const

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

begin(), QPaintDevice::paintingActive()
 Qt::LayoutDirection QPainter::layoutDirection ( ) const

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

QTextOption::textDirection(), setLayoutDirection(), drawText()
 const QMatrix & QPainter::matrix ( ) const
deprecated
 bool QPainter::matrixEnabled ( ) const
deprecated
 qreal QPainter::opacity ( ) const

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

setOpacity()
 QPaintEngine * QPainter::paintEngine ( ) const

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

isActive()
 const QPen & QPainter::pen ( ) const

Returns the painter's current pen.

setPen()
 QPaintDevice * QPainter::redirected ( const QPaintDevice * device, QPoint * point = nullptr )
deprecatedstatic
Deprecated:
This method is not required when using QWidget::render().

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

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

setRedirected(), restoreRedirected()
 RenderHints QPainter::renderHints ( ) const

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

setRenderHints(), testRenderHint()
 void QPainter::resetMatrix ( )
deprecated
Deprecated:
Resets any transformations that were made using translate(), scale(), shear(), rotate(), setWorldMatrix(), setViewport() and setWindow().

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

Coordinate Transformations
 void QPainter::resetTransform ( )

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

Coordinate Transformations
 void QPainter::restore ( )

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

save()
 void QPainter::restoreRedirected ( const QPaintDevice * device )
deprecatedstatic
Deprecated:

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

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

 void QPainter::rotate ( qreal angle )

Rotates the coordinate system the given angle clockwise.

setWorldTransform(), Coordinate Transformations
 void QPainter::save ( )

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.

restore()
 void QPainter::scale ( qreal sx, qreal sy )

Scales the coordinate system by (sx, sy).

setWorldTransform(), Coordinate Transformations
 void QPainter::setBackground ( const QBrush & brush )

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

background(), setBackgroundMode()
 void QPainter::setBackgroundMode ( 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.

In order to draw a bitmap or pixmap transparently, you must use QPixmap::setMask().

backgroundMode(), setBackground()
 void QPainter::setBrush ( const QBrush & brush )

Sets the painter's brush to the given brush. The painter's brush defines how shapes are filled.

brush()
 void QPainter::setBrush ( Qt::BrushStyle style )

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

 void QPainter::setBrushOrigin ( const QPoint & point )
inline

Sets the brush's origin to the given point.

 void QPainter::setBrushOrigin ( const QPointF & point )

Sets the brush origin to point. The brush origin specifies the (0, 0) coordinate of the painter's brush.

brushOrigin()
 void QPainter::setBrushOrigin ( int x, int y )
inline

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

 void QPainter::setClipPath ( const QPainterPath & path, Qt::ClipOperation operation = Qt::ReplaceClip )

Enables clipping, and sets the clip path for the painter to the given path, with the clip operation. The clip path is specified in logical (painter) coordinates.

clipPath(), clipRegion()
 void QPainter::setClipping ( bool enable )

Enables clipping if enable is true, otherwise disables clipping.

hasClipping()
 void QPainter::setClipRect ( const QRect & rect, Qt::ClipOperation operation = Qt::ReplaceClip )

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

 void QPainter::setClipRect ( const QRectF & rect, Qt::ClipOperation operation = Qt::ReplaceClip )

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

The clip rectangle is specified in logical (painter) coordinates.

clipRegion(), setClipping()
 void QPainter::setClipRect ( int x, int y, int w, int h, Qt::ClipOperation operation = Qt::ReplaceClip )
inline

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

 void QPainter::setClipRegion ( const QRegion & region, Qt::ClipOperation operation = 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. The clip region is given in logical coordinates.

clipRegion(), setClipRect()
 void QPainter::setCompositionMode ( CompositionMode mode )

Sets the composition mode to the given mode.

Warning
Only a QPainter operating on a QImage fully supports all composition modes. The RasterOp modes are supported for X11 as described in compositionMode().
compositionMode()
 void QPainter::setFont ( const QFont & font )

Sets the painter's font to the given font. This font is used by subsequent drawText() methods. The text color is the same as the pen color.

If you set a font that is not available, CopperSpice 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).

font(), drawText()
 void QPainter::setLayoutDirection ( Qt::LayoutDirection direction )

Sets the layout direction used by the painter when drawing text to the specified direction. The default is Qt::LayoutDirectionAuto, which will implicitly determine the direction from the text drawn.

QTextOption::setTextDirection(), layoutDirection(), drawText()
 void QPainter::setMatrix ( const QMatrix & matrix, bool combine = false )
deprecated
 void QPainter::setMatrixEnabled ( bool enable )
deprecated
 void QPainter::setOpacity ( qreal 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.

opacity()
 void QPainter::setPen ( const QColor & color )

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

 void QPainter::setPen ( const QPen & pen )

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.

pen()
 void QPainter::setPen ( Qt::PenStyle style )

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

 void QPainter::setRedirected ( const QPaintDevice * device, QPaintDevice * replacement, const QPoint & point = QPoint() )
deprecatedstatic
Deprecated:

Redirects all paint commands for the given paint device, to the replacement device. The optional point point 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.

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

redirected(), restoreRedirected()
 void QPainter::setRenderHint ( RenderHint hint, bool on = true )

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

setRenderHints(), renderHints()
 void QPainter::setRenderHints ( RenderHints hints, bool on = true )

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

setRenderHint(), renderHints()
 void QPainter::setTransform ( const 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.

transform(), setWorldTransform()
 void QPainter::setViewport ( const QRect & viewport )

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

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

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

viewport(), viewTransformEnabled(), Window-Viewport Conversion
 void QPainter::setViewport ( int x, int y, int w, int h )
inline

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

 void QPainter::setViewTransformEnabled ( bool enable )

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

viewTransformEnabled(), Window-Viewport Conversion
 void QPainter::setWindow ( const QRect & window )

Sets the painter's window to the given window, and enables view transformations. The window rectangle is part of the view transformation. The window specifies the logical coordinate system. The viewport() specifies the device coordinate system.

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

window(), viewTransformEnabled(), Window-Viewport Conversion
 void QPainter::setWindow ( int x, int y, int w, int h )
inline

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

 void QPainter::setWorldMatrix ( const QMatrix & matrix, bool combine = false )
deprecated
Deprecated:
Sets the transformation matrix to matrix and enables transformations.

It is advisable to use setWorldTransform() instead of this method 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:

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

void QPainter::rotate(qreal angle) {
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.

worldMatrix(), setWorldTransform()
 void QPainter::setWorldMatrixEnabled ( bool enable )

Enables transformations if enable is true, otherwise transformations are disabled. The world transformation matrix is not changed.

worldMatrixEnabled(), worldTransform(), Coordinate Transformations
 void QPainter::setWorldTransform ( const 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.

worldTransform(), transform(), setTransform()
 void QPainter::shear ( qreal sh, qreal sv )

Shears the coordinate system by (sh, sv).

setWorldTransform(), Coordinate Transformations
 void QPainter::strokePath ( const QPainterPath & path, const QPen & pen )

Draws the outline path with the pen specified by pen.

fillPath(), drawing
 bool QPainter::testRenderHint ( RenderHint hint ) const
inline

Returns true if hint is set, otherwise returns false.

renderHints(), setRenderHint()
 const QTransform & QPainter::transform ( ) const

Returns the world transformation matrix.

setTransform(), worldTransform()
 void QPainter::translate ( const QPoint & offset )
inline

Translates the coordinate system by the given offset.

 void QPainter::translate ( const QPointF & offset )

Translates the coordinate system by the given offset.

setWorldTransform(), Coordinate Transformations
 void QPainter::translate ( qreal dx, qreal dy )
inline

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

 QRect QPainter::viewport ( ) const

Returns the viewport rectangle.

setViewport(), setViewTransformEnabled()
 bool QPainter::viewTransformEnabled ( ) const

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

setViewTransformEnabled(), worldTransform()
 QRect QPainter::window ( ) const

Returns the window rectangle.

setWindow(), setViewTransformEnabled()
 const QMatrix & QPainter::worldMatrix ( ) const
deprecated
Deprecated:
Returns the world transformation matrix.

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