
We bake cookies in your browser for a better experience. Using this site means that you consent.Read More
TheQPainter class performs low-level painting on widgets and other paint devices.More...
| Header: | #include <QPainter> |
| Inherited By: |
Note: All functions in this class arereentrant.
| class | PixmapFragment |
| enum | CompositionMode { CompositionMode_SourceOver, CompositionMode_DestinationOver, CompositionMode_Clear, CompositionMode_Source, ..., RasterOp_SourceAndNotDestination } |
| enum | PixmapFragmentHint { OpaqueHint } |
| flags | PixmapFragmentHints |
| enum | RenderHint { Antialiasing, TextAntialiasing, SmoothPixmapTransform, HighQualityAntialiasing, NonCosmeticDefaultPen } |
| flags | RenderHints |
| QPainter() | |
| QPainter(QPaintDevice * device) | |
| ~QPainter() | |
| const QBrush & | background() const |
| Qt::BGMode | backgroundMode() const |
| bool | begin(QPaintDevice * device) |
| void | beginNativePainting() |
| QRectF | boundingRect(const QRectF & rectangle, int flags, const QString & text) |
| QRect | boundingRect(const QRect & rectangle, int flags, const QString & text) |
| QRect | boundingRect(int x, int y, int w, int h, int flags, const QString & text) |
| QRectF | boundingRect(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption()) |
| const QBrush & | brush() const |
| QPoint | brushOrigin() const |
| QRectF | clipBoundingRect() const |
| QPainterPath | clipPath() const |
| QRegion | clipRegion() const |
| QTransform | combinedTransform() const |
| CompositionMode | compositionMode() const |
| QPaintDevice * | device() const |
| const QTransform & | deviceTransform() const |
| void | drawArc(const QRectF & rectangle, int startAngle, int spanAngle) |
| void | drawArc(const QRect & rectangle, int startAngle, int spanAngle) |
| void | drawArc(int x, int y, int width, int height, int startAngle, int spanAngle) |
| void | drawChord(const QRectF & rectangle, int startAngle, int spanAngle) |
| void | drawChord(const QRect & rectangle, int startAngle, int spanAngle) |
| void | drawChord(int x, int y, int width, int height, int startAngle, int spanAngle) |
| void | drawConvexPolygon(const QPointF * points, int pointCount) |
| void | drawConvexPolygon(const QPoint * points, int pointCount) |
| void | drawConvexPolygon(const QPolygonF & polygon) |
| void | drawConvexPolygon(const QPolygon & polygon) |
| void | drawEllipse(const QRectF & rectangle) |
| void | drawEllipse(const QRect & rectangle) |
| void | drawEllipse(int x, int y, int width, int height) |
| void | drawEllipse(const QPointF & center, qreal rx, qreal ry) |
| void | drawEllipse(const QPoint & center, int rx, int ry) |
| void | drawGlyphRun(const QPointF & position, const QGlyphRun & glyphs) |
| void | drawImage(const QRectF & target, const QImage & image, const QRectF & source, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| void | drawImage(const QRect & target, const QImage & image, const QRect & source, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| void | drawImage(const QPointF & point, const QImage & image) |
| void | drawImage(const QPoint & point, const QImage & image) |
| void | drawImage(const QPointF & point, const QImage & image, const QRectF & source, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| void | drawImage(const QPoint & point, const QImage & image, const QRect & source, Qt::ImageConversionFlags flags = Qt::AutoColor) |
| void | drawImage(const QRectF & rectangle, const QImage & image) |
| void | drawImage(const QRect & rectangle, const QImage & image) |
| 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 QLineF & line) |
| void | drawLine(const QLine & 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 QLineF * lines, int lineCount) |
| void | drawLines(const QLine * lines, int lineCount) |
| void | drawLines(const QPointF * pointPairs, int lineCount) |
| void | drawLines(const QPoint * pointPairs, int lineCount) |
| void | drawLines(const QVector<QPointF> & pointPairs) |
| void | drawLines(const QVector<QPoint> & pointPairs) |
| void | drawLines(const QVector<QLineF> & lines) |
| void | drawLines(const QVector<QLine> & lines) |
| void | drawPath(const QPainterPath & path) |
| void | drawPicture(const QPointF & point, const QPicture & picture) |
| void | drawPicture(const QPoint & point, const QPicture & picture) |
| void | drawPicture(int x, int y, const QPicture & picture) |
| void | drawPie(const QRectF & rectangle, int startAngle, int spanAngle) |
| void | drawPie(const QRect & rectangle, int startAngle, int spanAngle) |
| void | drawPie(int x, int y, int width, int height, int startAngle, int spanAngle) |
| void | drawPixmap(const QRectF & target, const QPixmap & pixmap, const QRectF & source) |
| void | drawPixmap(const QRect & target, const QPixmap & pixmap, const QRect & source) |
| void | drawPixmap(const QPointF & point, const QPixmap & pixmap, const QRectF & source) |
| void | drawPixmap(const QPoint & point, const QPixmap & pixmap, const QRect & source) |
| void | drawPixmap(const QPointF & point, const QPixmap & pixmap) |
| void | drawPixmap(const QPoint & point, const QPixmap & pixmap) |
| void | drawPixmap(int x, int y, const QPixmap & pixmap) |
| void | drawPixmap(const QRect & rectangle, const QPixmap & pixmap) |
| void | drawPixmap(int x, int y, int width, int height, 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 | drawPixmap(int x, int y, const QPixmap & pixmap, int sx, int sy, int sw, int sh) |
| void | drawPixmapFragments(const PixmapFragment * fragments, int fragmentCount, const QPixmap & pixmap, PixmapFragmentHints hints = 0) |
| void | drawPixmapFragments(const QRectF * targetRects, const QRectF * sourceRects, int fragmentCount, const QPixmap & pixmap, PixmapFragmentHints hints = 0) |
| void | drawPoint(const QPointF & position) |
| void | drawPoint(const QPoint & position) |
| void | drawPoint(int x, int y) |
| void | drawPoints(const QPointF * points, int pointCount) |
| void | drawPoints(const QPoint * points, int pointCount) |
| void | drawPoints(const QPolygonF & points) |
| void | drawPoints(const QPolygon & points) |
| void | drawPolygon(const QPointF * points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill) |
| void | drawPolygon(const QPoint * points, int pointCount, Qt::FillRule fillRule = Qt::OddEvenFill) |
| void | drawPolygon(const QPolygonF & points, Qt::FillRule fillRule = Qt::OddEvenFill) |
| void | drawPolygon(const QPolygon & points, Qt::FillRule fillRule = Qt::OddEvenFill) |
| void | drawPolyline(const QPointF * points, int pointCount) |
| void | drawPolyline(const QPoint * points, int pointCount) |
| void | drawPolyline(const QPolygonF & points) |
| void | drawPolyline(const QPolygon & points) |
| void | drawRect(const QRectF & rectangle) |
| void | drawRect(const QRect & rectangle) |
| void | drawRect(int x, int y, int width, int height) |
| void | drawRects(const QRectF * rectangles, int rectCount) |
| void | drawRects(const QRect * rectangles, int rectCount) |
| void | drawRects(const QVector<QRectF> & rectangles) |
| void | drawRects(const QVector<QRect> & rectangles) |
| void | drawRoundedRect(const QRectF & rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize) |
| void | drawRoundedRect(const QRect & rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize) |
| void | drawRoundedRect(int x, int y, int w, int h, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize) |
| void | drawStaticText(const QPointF & topLeftPosition, const QStaticText & staticText) |
| void | drawStaticText(const QPoint & topLeftPosition, const QStaticText & staticText) |
| void | drawStaticText(int left, int top, const QStaticText & staticText) |
| void | drawText(const QPointF & position, const QString & text) |
| void | drawText(const QPoint & position, const QString & text) |
| void | drawText(const QRectF & rectangle, int flags, const QString & text, QRectF * boundingRect = 0) |
| void | drawText(const QRect & rectangle, int flags, const QString & text, QRect * boundingRect = 0) |
| void | drawText(int x, int y, const QString & text) |
| void | drawText(int x, int y, int width, int height, int flags, const QString & text, QRect * boundingRect = 0) |
| void | drawText(const QRectF & rectangle, const QString & text, const QTextOption & option = QTextOption()) |
| void | drawTiledPixmap(const QRectF & rectangle, const QPixmap & pixmap, const QPointF & position = QPointF()) |
| void | drawTiledPixmap(const QRect & rectangle, const QPixmap & pixmap, const QPoint & position = QPoint()) |
| void | drawTiledPixmap(int x, int y, int width, int height, const QPixmap & pixmap, int sx = 0, int sy = 0) |
| bool | end() |
| void | endNativePainting() |
| void | eraseRect(const QRectF & rectangle) |
| void | eraseRect(const QRect & rectangle) |
| void | eraseRect(int x, int y, int width, int height) |
| void | fillPath(const QPainterPath & path, const QBrush & brush) |
| void | fillRect(const QRectF & rectangle, const QBrush & brush) |
| void | fillRect(int x, int y, int width, int height, Qt::BrushStyle style) |
| void | fillRect(const QRect & rectangle, Qt::BrushStyle style) |
| void | fillRect(const QRectF & rectangle, Qt::BrushStyle style) |
| void | fillRect(const QRect & rectangle, const QBrush & brush) |
| void | fillRect(const QRect & rectangle, const QColor & color) |
| void | fillRect(const QRectF & rectangle, const QColor & color) |
| void | fillRect(int x, int y, int width, int height, const QBrush & brush) |
| void | fillRect(int x, int y, int width, int height, const QColor & color) |
| void | fillRect(int x, int y, int width, int height, Qt::GlobalColor color) |
| void | fillRect(const QRect & rectangle, Qt::GlobalColor color) |
| void | fillRect(const QRectF & rectangle, Qt::GlobalColor color) |
| const QFont & | font() const |
| QFontInfo | fontInfo() const |
| QFontMetrics | fontMetrics() const |
| bool | hasClipping() const |
| void | initFrom(const QWidget * widget) |
| bool | isActive() const |
| Qt::LayoutDirection | layoutDirection() const |
| qreal | opacity() const |
| QPaintEngine * | paintEngine() const |
| const QPen & | pen() const |
| RenderHints | renderHints() const |
| 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 QPointF & position) |
| void | setBrushOrigin(const QPoint & position) |
| void | setBrushOrigin(int x, int y) |
| void | setClipPath(const QPainterPath & path, Qt::ClipOperation operation = Qt::ReplaceClip) |
| void | setClipRect(const QRectF & rectangle, Qt::ClipOperation operation = Qt::ReplaceClip) |
| void | setClipRect(int x, int y, int width, int height, Qt::ClipOperation operation = Qt::ReplaceClip) |
| void | setClipRect(const QRect & rectangle, Qt::ClipOperation operation = Qt::ReplaceClip) |
| void | setClipRegion(const QRegion & region, Qt::ClipOperation operation = Qt::ReplaceClip) |
| void | setClipping(bool enable) |
| void | setCompositionMode(CompositionMode mode) |
| void | setFont(const QFont & font) |
| void | setLayoutDirection(Qt::LayoutDirection direction) |
| void | setOpacity(qreal opacity) |
| void | setPen(const QPen & pen) |
| void | setPen(const QColor & color) |
| 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 | setViewTransformEnabled(bool enable) |
| void | setViewport(const QRect & rectangle) |
| void | setViewport(int x, int y, int width, int height) |
| void | setWindow(const QRect & rectangle) |
| void | setWindow(int x, int y, int width, int height) |
| 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 QTransform & | transform() const |
| void | translate(const QPointF & offset) |
| void | translate(const QPoint & offset) |
| void | translate(qreal dx, qreal dy) |
| bool | viewTransformEnabled() const |
| QRect | viewport() const |
| QRect | window() const |
| bool | worldMatrixEnabled() const |
| const QTransform & | worldTransform() const |
TheQPainter 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 theQPaintDevice class.
The common use ofQPainter 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 theQPainter 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 ofQPainter is drawing, but the class also provide several functions that allows you to customizeQPainter'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.
TheisActive() function indicates whether the painter is active. A painter is activated by thebegin() function and the constructor that takes aQPaintDevice argument. Theend() function, and the destructor, deactivates it.
Together with theQPaintDevice andQPaintEngine 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 aQPainter.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, andpaintEngine() returns the paint engine that the painter is currently operating on. For more information, see thePaint System.
Sometimes it is desirable to make someone else paint on an unusualQPaintDevice.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 theQt::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.
There are several settings that you can customize to makeQPainter draw according to your preferences:
Note that some of these settings mirror settings in some paint devices, e.g.QWidget::font(). TheQPainter::begin() function (or equivalently theQPainter constructor) copies these attributes from the paint device.
You can at any time save theQPainter's state by calling thesave() function which saves all the available settings on an internal stack. Therestore() function pops them back.
QPainter provides functions to draw most primitives:drawPoint(),drawPoints(),drawLine(),drawRect(),drawRoundedRect(),drawEllipse(),drawArc(),drawPie(),drawChord(),drawPolyline(),drawPolygon(),drawConvexPolygon() anddrawCubicBezier(). The two convenience functions,drawRects() anddrawLines(), draw the given number of rectangles or lines in the given array ofQRects orQLines using the current pen and brush.
TheQPainter class also provides thefillRect() function which fills the givenQRect, with the givenQBrush, and theeraseRect() function that erases the area inside the given rectangle.
All of these functions have both integer and floating point versions.
![]() | Basic Drawing Example TheBasic Drawing example shows how to display basic graphics primitives in a variety of styles using theQPainter class. |
If you need to draw a complex shape, especially if you need to do so repeatedly, consider creating aQPainterPath and drawing it usingdrawPath().
| Painter Paths example TheQPainterPath class provides a container for painting operations, enabling graphical shapes to be constructed and reused. ThePainter Paths example shows how painter paths can be used to build complex shapes for rendering. | ![]() |
QPainter also provides thefillPath() function which fills the givenQPainterPath with the givenQBrush, and thestrokePath() function that draws the outline of the given path (i.e. strokes the path).
See also theVector Deformation demo which shows how to use advanced vector techniques to draw text using aQPainterPath, theGradients demo which shows the different types of gradients that are available in Qt, and thePath 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.
There are functions to draw pixmaps/images, namelydrawPixmap(),drawImage() anddrawTiledPixmap(). BothdrawPixmap() anddrawImage() produce the same result, except thatdrawPixmap() is faster on-screen whiledrawImage() may be faster on aQPrinter or other devices.
Text drawing is done usingdrawText(). When you need fine-grained positioning,boundingRect() tells you where a givendrawText() command will draw.
There is adrawPicture() function that draws the contents of an entireQPicture. ThedrawPicture() function is the only function that disregards all the painter's settings asQPicture has its own settings.
To get the optimal rendering result usingQPainter, you should use the platform independentQImage as paint device; i.e. usingQImage will ensure that the result has an identical pixel representation on any platform.
TheQPainter class also provides a means of controlling the rendering quality through itsRenderHint 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 theQPainter::Antialiasing render hint.
![]() | Concentric Circles Example TheConcentric 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. |
TheRenderHint enum specifies flags toQPainter 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 theQPainter::SmoothPixmapTransform indicates that the engine should use a smooth pixmap transformation algorithm.HighQualityAntialiasing is anOpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing.
TherenderHints() function returns a flag that specifies the rendering hints that are set for this painter. Use thesetRenderHint() function to set or clear the currently setRenderHints.
Normally, theQPainter operates on the device's own coordinate system (usually pixels), butQPainter has good support for coordinate transformations.
The most commonly used transformations are scaling, rotation, translation and shearing. Use thescale() function to scale the coordinate system by a given offset, therotate() function to rotate it clockwise andtranslate() to translate it (i.e. adding a given offset to the points). You can also twist the coordinate system around the origin using theshear() function. See theAffine Transformations demo for a visualization of a sheared coordinate system.
See also theTransformations example which shows how transformations influence the way thatQPainter renders graphics primitives. In particular it shows how the order of transformations affects the result.
| Affine Transformations Demo TheAffine 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 transformationworldTransform(). A matrix transforms a point in the plane to another point. For more information about the transformation matrix, see theCoordinate System andQTransform documentation.
ThesetWorldTransform() function can replace or add to the currently setworldTransform(). TheresetTransform() function resets any transformations that were made usingtranslate(),scale(),shear(),rotate(),setWorldTransform(),setViewport() andsetWindow() functions. ThedeviceTransform() 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 withQPainter, 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 byQPainter'scombinedTransform(), a combination ofviewport() andwindow() andworldTransform(). Theviewport() represents the physical coordinates specifying an arbitrary rectangle, thewindow() describes the same rectangle in logical coordinates, and theworldTransform() is identical with the transformation matrix.
See alsoCoordinate System
QPainter can clip any drawing operation to a rectangle, a region, or a vector path. The current clip is available using the functionsclipRegion() andclipPath(). Whether paths or regions are preferred (faster) depends on the underlyingpaintEngine(). For example, theQImage paint engine prefers paths while the X11 paint engine prefers regions. Setting a clip is done in the painters logical coordinates.
AfterQPainter'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 ofclipRegion() orhasClipping().
QPainter provides theCompositionMode 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 areSource andSourceOver.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. InSourceOver composition mode, the source object is transparent and is drawn on top of the destination.
Note that composition transformation operates pixelwise. For that reason, there is a difference between using the graphic primitive itself and its bounding rectangle: The bounding rect contains pixels with alpha == 0 (i.e the pixels surrounding the primitive). These pixels will overwrite the other image's pixels, affectively clearing those, while the primitive only overwrites its own area.
![]() | Composition Modes Demo TheComposition Modes demo, available in Qt's demo directory, allows you to experiment with the various composition modes and see the results immediately. |
If you are using coordinates with Qt's raster-based paint engine, it is important to note that, while coordinates greater than +/- 215 can be used, any painting performed with coordinates outside this range is not guaranteed to be shown; the drawing may be clipped. This is due to the use ofshort int in the implementation.
The outlines generated by Qt's stroker are only an approximation when dealing with curved shapes. It is in most cases impossible to represent the outline of a bezier curve segment using another bezier curve segment, and so Qt approximates the curve outlines by using several smaller curves. For performance reasons there is a limit to how many curves Qt uses for these outlines, and thus when using large pen widths or scales the outline error increases. To generate outlines with smaller errors it is possible to use theQPainterPathStroker class, which has the setCurveThreshold member function which let's the user specify the error tolerance. Another workaround is to convert the paths to polygons first and then draw the polygons instead.
QPainter is a rich framework that allows developers to do a great variety of graphical operations, such as gradients, composition modes and vector graphics. AndQPainter can do this across a variety of different hardware and software stacks. Naturally the underlying combination of hardware and software has some implications for performance, and ensuring that every single operation is fast in combination with all the various combinations of composition modes, brushes, clipping, transformation, etc, is close to an impossible task because of the number of permutations. As a compromise we have selected a subset of theQPainter API and backends, where performance is guaranteed to be as good as we can sensibly get it for the given combination of hardware and software.
The backends we focus on as high-performance engines are:
-graphicssystem raster on the command line-graphicssystem opengl on the command line when the underlying system supports it.-graphicssystem openvg on the command line when the underlying system supports it.These operations are:
drawPixmap() in combination with simple transformations and opacity with non-smooth transformation mode (QPainter::SmoothPixmapTransform not enabled as a render hint).QPainter::CompositionMode_Source andQPainter::CompositionMode_SourceOverThis list gives an indication of which features to safely use in an application where performance is critical. For certain setups, other operations may be fast too, but before making extensive use of them, it is recommended to benchmark and verify them on the system where the software will run in the end. There are also cases where expensive operations are ok to use, for instance when the result is cached in aQPixmap.
See alsoQPaintDevice,QPaintEngine,QtSvg Module,Basic Drawing Example, andDrawing Utility Functions.
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 aQImage. The RasterOp denoted blend modes arenot supported for pens and brushes with alpha components. Also, turning on theQPainter::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 aQImage, the image format must be set toFormat_ARGB32Premultiplied orFormat_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. |
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 | 26 | Does a bitwise XOR operation on the source and destination pixels (src XOR dst). |
QPainter::RasterOp_NotSourceAndNotDestination | 27 | Does a bitwise NOR operation on the source and destination pixels ((NOT src) AND (NOT dst)). |
QPainter::RasterOp_NotSourceOrNotDestination | 28 | Does a bitwise NAND operation on the source and destination pixels ((NOT src) OR (NOT 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)). |
See alsocompositionMode(),setCompositionMode(),Composition Modes, andImage Composition Example.
| Constant | Value | Description |
|---|---|---|
QPainter::OpaqueHint | 0x01 | Indicates that the pixmap fragments to be drawn are opaque. Opaque fragments are potentially faster to draw. |
This enum was introduced or modified in Qt 4.7.
The PixmapFragmentHints type is a typedef forQFlags<PixmapFragmentHint>. It stores an OR combination of PixmapFragmentHint values.
See alsoQPainter::drawPixmapFragments() andQPainter::PixmapFragment.
Renderhints are used to specify flags toQPainter 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. To forcibly disable antialiasing for text, do not use this hint. Instead, setQFont::NoAntialias on your font's style strategy. |
QPainter::SmoothPixmapTransform | 0x04 | Indicates that the engine should use a smooth pixmap transformation algorithm (such as bilinear) rather than nearest neighbor. |
QPainter::HighQualityAntialiasing | 0x08 | AnOpenGL-specific rendering hint indicating that the engine should use fragment programs and offscreen rendering for antialiasing. |
QPainter::NonCosmeticDefaultPen | 0x10 | The engine should interpret pens with a width of 0 (which otherwise enablesQPen::isCosmetic()) as being a non-cosmetic pen with a width of 1. |
The RenderHints type is a typedef forQFlags<RenderHint>. It stores an OR combination of RenderHint values.
See alsorenderHints(),setRenderHint(),Rendering Quality, andConcentric Circles Example.
Constructs a painter.
Constructs a painter that begins painting the paintdevice immediately.
This constructor is convenient for short-lived painters, e.g. in aQWidget::paintEvent() and should be used only once. The constructor callsbegin() for you and theQPainter destructor automatically callsend().
Here's an example usingbegin() andend():
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 usebegin() andend() to paint on external devices, e.g. printers.
Destroys the painter.
Returns the current background brush.
See alsosetBackground() andSettings.
Returns the current background mode.
See alsosetBackgroundMode() andSettings.
Begins painting the paintdevice 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 0QPixmap 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 thatend() is automatically done at destruction.
Warning: A paint device can only be painted by one painter at a time.
Warning: Painting on aQImage with the formatQImage::Format_Indexed8 is not supported.
Flushes the painting pipeline and prepares for the user issuing commands directly to the underlying graphics context. Must be followed by a call toendNativePainting().
Note that only the states the underlying paint engine changes will be reset to their respective default states. The states we reset may change from release to release. The following states are currently reset in theOpenGL 2 engine:
If, for example, theOpenGL polygon mode is changed by the user inside a beginNativePaint()/endNativePainting() block, it will not be reset to the default state byendNativePainting(). Here is an example that shows intermixing of painter commands and rawOpenGL commands:
QPainter painter(this);painter.fillRect(0,0,128,128,Qt::green);painter.beginNativePainting();glEnable(GL_SCISSOR_TEST);glScissor(0,0,64,64);glClearColor(1,0,0,1);glClear(GL_COLOR_BUFFER_BIT);glDisable(GL_SCISSOR_TEST);painter.endNativePainting();
This function was introduced in Qt 4.6.
See alsoendNativePainting().
Returns the bounding rectangle of thetext as it will appear when drawn inside the givenrectangle with the specifiedflags using the currently setfont(); i.e the function tells you where thedrawText() function will draw when given the same arguments.
If thetext does not fit within the givenrectangle using the specifiedflags, the function returns the required rectangle.
Theflags 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.
See alsodrawText(),Qt::Alignment, andQt::TextFlag.
This is an overloaded function.
Returns the bounding rectangle of thetext as it will appear when drawn inside the givenrectangle with the specifiedflags using the currently setfont().
This is an overloaded function.
Returns the bounding rectangle of the giventext as it will appear when drawn inside the rectangle beginning at the point (x,y) with widthw and heighth.
This is an overloaded function.
Instead of specifying flags as a bitwise OR of theQt::AlignmentFlag andQt::TextFlag, this overloaded function takes anoption argument. TheQTextOption class provides a description of general rich text properties.
See alsoQTextOption.
Returns the painter's current brush.
See alsoQPainter::setBrush() andSettings.
Returns the currently set brush origin.
See alsosetBrushOrigin() andSettings.
Returns the bounding rectangle of the current clip if there is a clip; otherwise returns an empty rectangle. Note that the clip region is given in logical coordinates.
The bounding rectangle is not guaranteed to be tight.
This function was introduced in Qt 4.8.
See alsosetClipRect(),setClipPath(), andsetClipRegion().
Returns the currently clip as a path. Note that the clip path is given in logical coordinates.
Warning:QPainter does not store the combined clip explicitly as this is handled by the underlyingQPaintEngine, so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.
See alsosetClipPath(),clipRegion(), andsetClipping().
Returns the currently set clip region. Note that the clip region is given in logical coordinates.
Warning:QPainter does not store the combined clip explicitly as this is handled by the underlyingQPaintEngine, so the path is recreated on demand and transformed to the current logical coordinate system. This is potentially an expensive operation.
See alsosetClipRegion(),clipPath(), andsetClipping().
Returns the transformation matrix combining the current window/viewport and world transformation.
See alsosetWorldTransform(),setWindow(), andsetViewport().
Returns the current composition mode.
See alsoCompositionMode andsetCompositionMode().
Returns the paint device on which this painter is currently painting, or 0 if the painter is not active.
See alsoisActive().
Returns the matrix that transforms from logical coordinates to device coordinates of the platform dependent paint device.
This function isonly needed when using platform painting commands on the platform dependent handle (Qt::HANDLE), and the platform does not do transformations nativly.
TheQPaintEngine::PaintEngineFeature enum can be queried to determine whether the platform performs the transformations or not.
See alsoworldTransform() andQPaintEngine::hasFeature().
Draws the arc defined by the givenrectangle,startAngle andspanAngle.
ThestartAngle andspanAngle 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 alsodrawPie(),drawChord(), andCoordinate System.
This is an overloaded function.
Draws the arc defined by the givenrectangle,startAngle andspanAngle.
This is an overloaded function.
Draws the arc defined by the rectangle beginning at (x,y) with the specifiedwidth andheight, and the givenstartAngle andspanAngle.
Draws the chord defined by the givenrectangle,startAngle andspanAngle. The chord is filled with the currentbrush().
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 alsodrawArc(),drawPie(), andCoordinate System.
This is an overloaded function.
Draws the chord defined by the givenrectangle,startAngle andspanAngle.
This is an overloaded function.
Draws the chord defined by the rectangle beginning at (x,y) with the specifiedwidth andheight, and the givenstartAngle andspanAngle.
Draws the convex polygon defined by the firstpointCount points in the arraypoints using the current pen.
![]() | staticconstQPointF 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 currentbrush(). 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 thedrawPolygon() function.
See alsodrawPolygon(),drawPolyline(), andCoordinate System.
This is an overloaded function.
Draws the convex polygon defined by the firstpointCount points in the arraypoints using the current pen.
This is an overloaded function.
Draws the convex polygon defined bypolygon using the current pen and brush.
This is an overloaded function.
Draws the convex polygon defined bypolygon using the current pen and brush.
Draws the ellipse defined by the givenrectangle.
A filled ellipse has a size ofrectangle.size(). A stroked ellipse has a size ofrectangle.size() plus the pen width.
See alsodrawPie() andCoordinate System.
This is an overloaded function.
Draws the ellipse defined by the givenrectangle.
This is an overloaded function.
Draws the ellipse defined by the rectangle beginning at (x,y) with the givenwidth andheight.
This is an overloaded function.
Draws the ellipse positioned atcenter with radiirx andry.
This function was introduced in Qt 4.4.
This is an overloaded function.
Draws the ellipse positioned atcenter with radiirx andry.
This function was introduced in Qt 4.4.
Draws the specifiedglyphs at the givenposition. Theposition gives the edge of the baseline for the string of glyphs. The glyphs will be retrieved from the font selected byglyphs and at offsets given by the positions inglyphs.
This function was introduced in Qt 4.8.
See alsoQGlyphRun::setRawFont(),QGlyphRun::setPositions(), andQGlyphRun::setGlyphIndexes().
Draws the rectangular portionsource of the givenimage into thetarget rectangle in the paint device.
Note: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 theflags 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); |
See alsodrawPixmap().
This is an overloaded function.
Draws the rectangular portionsource of the givenimage into thetarget rectangle in the paint device.
Note:The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
This is an overloaded function.
Draws the givenimage at the givenpoint.
This is an overloaded function.
Draws the givenimage at the givenpoint.
This is an overloaded function.
Draws the rectangular portionsource of the givenimage with its origin at the givenpoint.
This is an overloaded function.
Draws the rectangular portionsource of the givenimage with its origin at the givenpoint.
This is an overloaded function.
Draws the givenimage into the givenrectangle.
Note:The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
This is an overloaded function.
Draws the givenimage into the givenrectangle.
Note:The image is scaled to fit the rectangle, if both the image and rectangle size disagree.
This is an overloaded function.
Draws an image at (x,y) by copying a part ofimage 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 inimage 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.
Draws a line defined byline.
See alsodrawLines(),drawPolyline(), andCoordinate System.
This is an overloaded function.
Draws a line defined byline.
This is an overloaded function.
Draws a line fromp1 top2.
This is an overloaded function.
Draws a line fromp1 top2.
This is an overloaded function.
Draws a line from (x1,y1) to (x2,y2) and sets the current pen position to (x2,y2).
Draws the firstlineCount lines in the arraylines using the current pen.
See alsodrawLine() anddrawPolyline().
This is an overloaded function.
Draws the firstlineCount lines in the arraylines using the current pen.
This is an overloaded function.
Draws the firstlineCount lines in the arraypointPairs using the current pen. The lines are specified as pairs of points so the number of entries inpointPairs must be at leastlineCount * 2.
This is an overloaded function.
Draws the firstlineCount lines in the arraypointPairs using the current pen.
This is an overloaded function.
Draws a line for each pair of points in the vectorpointPairs using the current pen. If there is an odd number of points in the array, the last point will be ignored.
This is an overloaded function.
Draws a line for each pair of points in the vectorpointPairs using the current pen.
This is an overloaded function.
Draws the set of lines defined by the listlines using the current pen and brush.
This is an overloaded function.
Draws the set of lines defined by the listlines using the current pen and brush.
Draws the given painterpath 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 alsothe Painter Paths example andthe Vector Deformation demo.
Replays the givenpicture at the givenpoint.
TheQPicture class is a paint device that records and replaysQPainter 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 asQPicture::play() when called withpoint =QPoint(0, 0).
QPicture picture;QPointF point(10.0,20.0)picture.load("drawing.pic");QPainter painter(this);painter.drawPicture(0,0, picture); |
See alsoQPicture::play().
This is an overloaded function.
Replays the givenpicture at the givenpoint.
This is an overloaded function.
Draws the givenpicture at point (x,y).
Draws a pie defined by the givenrectangle,startAngle and andspanAngle.
The pie is filled with the currentbrush().
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 alsodrawEllipse(),drawChord(), andCoordinate System.
This is an overloaded function.
Draws a pie defined by the givenrectangle,startAngle and andspanAngle.
This is an overloaded function.
Draws the pie defined by the rectangle beginning at (x,y) with the specifiedwidth andheight, and the givenstartAngle andspanAngle.
Draws the rectangular portionsource of the givenpixmap into the giventarget in the paint device.
Note:The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
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); |
Ifpixmap is aQBitmap it is drawn with the bits that are "set" using the pens color. IfbackgroundMode isQt::OpaqueMode, the "unset" bits are drawn using the color of the background brush; ifbackgroundMode isQt::TransparentMode, the "unset" bits are transparent. Drawing bitmaps with gradient or texture colors is not supported.
See alsodrawImage().
This is an overloaded function.
Draws the rectangular portionsource of the givenpixmap into the giventarget in the paint device.
Note:The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
This is an overloaded function.
Draws the rectangular portionsource of the givenpixmap with its origin at the givenpoint.
This is an overloaded function.
Draws the rectangular portionsource of the givenpixmap with its origin at the givenpoint.
This is an overloaded function.
Draws the givenpixmap with its origin at the givenpoint.
This is an overloaded function.
Draws the givenpixmap with its origin at the givenpoint.
This is an overloaded function.
Draws the givenpixmap at position (x,y).
This is an overloaded function.
Draws the givenpixmap into the givenrectangle.
Note:The pixmap is scaled to fit the rectangle, if both the pixmap and rectangle size disagree.
This is an overloaded function.
Draws thepixmap into the rectangle at position (x,y) with the givenwidth andheight.
This is an overloaded function.
Draws the rectangular portion with the origin (sx,sy), widthsw and heightsh, of the givenpixmap , at the point (x,y), with a width ofw and a height ofh. If sw or sh are equal to zero the width/height of the pixmap is used and adjusted by the offset sx/sy;
This is an overloaded function.
Draws a pixmap at (x,y) by copying a part of the givenpixmap 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 inpixmap 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.
This function is used to drawpixmap, or a sub-rectangle ofpixmap, at multiple positions with different scale, rotation and opacity.fragments is an array offragmentCount elements specifying the parameters used to draw each pixmap fragment. Thehints parameter can be used to pass in drawing hints.
This function is potentially faster than multiple calls todrawPixmap(), since the backend can optimize state changes.
This function was introduced in Qt 4.7.
See alsoQPainter::PixmapFragment andQPainter::PixmapFragmentHint.
This function is used to draw the samepixmap with multiple target and source rectangles specified bytargetRects. IfsourceRects is 0, the whole pixmap will be rendered at each of the target rectangles. Thehints parameter can be used to pass in drawing hints.
This function is potentially faster than multiple calls todrawPixmap(), since the backend can optimize state changes.
This function was introduced in Qt 4.8.
See alsoQPainter::PixmapFragmentHint.
Draws a single point at the givenposition using the current pen's color.
See alsoCoordinate System.
This is an overloaded function.
Draws a single point at the givenposition using the current pen's color.
This is an overloaded function.
Draws a single point at position (x,y).
Draws the firstpointCount points in the arraypoints using the current pen's color.
See alsoCoordinate System.
This is an overloaded function.
Draws the firstpointCount points in the arraypoints using the current pen's color.
This is an overloaded function.
Draws the points in the vectorpoints.
This is an overloaded function.
Draws the points in the vectorpoints.
Draws the polygon defined by the firstpointCount points in the arraypoints using the current pen and brush.
![]() | staticconstQPointF 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 currentbrush().
IffillRule isQt::WindingFill, the polygon is filled using the winding fill algorithm. IffillRule isQt::OddEvenFill, the polygon is filled using the odd-even fill algorithm. SeeQt::FillRule for a more detailed description of these fill rules.
See alsodrawConvexPolygon(),drawPolyline(), andCoordinate System.
This is an overloaded function.
Draws the polygon defined by the firstpointCount points in the arraypoints.
This is an overloaded function.
Draws the polygon defined by the givenpoints using the fill rulefillRule.
This is an overloaded function.
Draws the polygon defined by the givenpoints using the fill rulefillRule.
Draws the polyline defined by the firstpointCount points inpoints using the current pen.
Note that unlike thedrawPolygon() function the last point isnot connected to the first, neither is the polyline filled.
staticconstQPointF 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 alsodrawLines(),drawPolygon(), andCoordinate System.
This is an overloaded function.
Draws the polyline defined by the firstpointCount points inpoints using the current pen.
This is an overloaded function.
Draws the polyline defined by the givenpoints using the current pen.
This is an overloaded function.
Draws the polyline defined by the givenpoints using the current pen.
Draws the currentrectangle with the current pen and brush.
A filled rectangle has a size ofrectangle.size(). A stroked rectangle has a size ofrectangle.size() plus the pen width.
See alsodrawRects(),drawPolygon(), andCoordinate System.
This is an overloaded function.
Draws the currentrectangle with the current pen and brush.
This is an overloaded function.
Draws a rectangle with upper left corner at (x,y) and with the givenwidth andheight.
Draws the firstrectCount of the givenrectangles using the current pen and brush.
See alsodrawRect().
This is an overloaded function.
Draws the firstrectCount of the givenrectangles using the current pen and brush.
This is an overloaded function.
Draws the givenrectangles using the current pen and brush.
This is an overloaded function.
Draws the givenrectangles using the current pen and brush.
Draws the given rectanglerect with rounded corners.
ThexRadius andyRadius arguments specify the radii of the ellipses defining the corners of the rounded rectangle. Whenmode isQt::RelativeSize,xRadius andyRadius 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); |
This function was introduced in Qt 4.4.
This is an overloaded function.
Draws the given rectanglerect with rounded corners.
This function was introduced in Qt 4.4.
This is an overloaded function.
Draws the given rectanglex,y,w,h with rounded corners.
This function was introduced in Qt 4.4.
Draws the givenstaticText at the giventopLeftPosition.
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 theQStaticText, then the layout will have to be recalculated. UseQStaticText::prepare() to initializestaticText with the font and transformation with which it will later be drawn.
IftopLeftPosition is not the same as whenstaticText was initialized, or when it was last drawn, then there will be a slight overhead when translating the text to its new position.
Note:If the painter's transformation is not affine, thenstaticText will be drawn using regular calls todrawText(), losing any potential for performance improvement.
Note:The y-position is used as the top of the font.
This function was introduced in Qt 4.7.
See alsoQStaticText.
This is an overloaded function.
Draws thestaticText at thetopLeftPosition.
Note:The y-position is used as the top of the font.
This function was introduced in Qt 4.7.
This is an overloaded function.
Draws thestaticText at coordinatesleft andtop.
Note:The y-position is used as the top of the font.
This function was introduced in Qt 4.7.
Draws the giventext with the currently defined text direction, beginning at the givenposition.
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.
By default,QPainter draws text anti-aliased.
Note:The y-position is used as the baseline of the font.
This is an overloaded function.
Draws the giventext with the currently defined text direction, beginning at the givenposition.
By default,QPainter draws text anti-aliased.
Note:The y-position is used as the baseline of the font.
This is an overloaded function.
Draws the giventext within the providedrectangle.
TheboundingRect (if not null) is set to the what the bounding rectangle should be in order to enclose the whole text. Theflags argument is a bitwise OR of the following flags:
By default,QPainter draws text anti-aliased.
Note:The y-coordinate ofrectangle is used as the top of the font.
See alsoQt::AlignmentFlag,Qt::TextFlag,boundingRect(), andlayoutDirection().
This is an overloaded function.
Draws the giventext within the providedrectangle according to the specifiedflags. TheboundingRect (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.
Note:The y-coordinate ofrectangle is used as the top of the font.
This is an overloaded function.
Draws the giventext at position (x,y), using the painter's currently defined text direction.
By default,QPainter draws text anti-aliased.
Note:The y-position is used as the baseline of the font.
This is an overloaded function.
Draws the giventext within the rectangle with origin (x,y),width andheight.
TheboundingRect (if not null) is set to the actual bounding rectangle of the output. Theflags argument is a bitwise OR of the following flags:
By default,QPainter draws text anti-aliased.
Note:The y-position is used as the top of the font.
See alsoQt::AlignmentFlag andQt::TextFlag.
This is an overloaded function.
Draws the giventext in therectangle specified using theoption to control its positioning and orientation.
By default,QPainter draws text anti-aliased.
Note:The y-coordinate ofrectangle is used as the top of the font.
Draws a tiledpixmap, inside the givenrectangle with its origin at the givenposition.
Calling drawTiledPixmap() is similar to callingdrawPixmap() several times to fill (tile) an area with a pixmap, but is potentially much more efficient depending on the underlying window system.
See alsodrawPixmap().
This is an overloaded function.
Draws a tiledpixmap, inside the givenrectangle with its origin at the givenposition.
This is an overloaded function.
Draws a tiledpixmap in the specified rectangle.
(x,y) specifies the top-left point in the paint device that is to be drawn onto; with the givenwidth andheight. (sx,sy) specifies the top-left point in thepixmap that is to be drawn; this defaults to (0, 0).
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 alsobegin() andisActive().
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.
This function was introduced in Qt 4.6.
See alsobeginNativePainting().
Erases the area inside the givenrectangle. Equivalent to calling
fillRect(rectangle, background()).
See alsofillRect().
This is an overloaded function.
Erases the area inside the givenrectangle.
This is an overloaded function.
Erases the area inside the rectangle beginning at (x,y) with the givenwidth andheight.
Fills the givenpath using the givenbrush. The outline is not drawn.
Alternatively, you can specify aQColor instead of aQBrush; theQBrush constructor (taking aQColor argument) will automatically create a solid pattern brush.
See alsodrawPath().
Fills the givenrectangle with thebrush specified.
Alternatively, you can specify aQColor instead of aQBrush; theQBrush constructor (taking aQColor argument) will automatically create a solid pattern brush.
See alsodrawRect().
This is an overloaded function.
Fills the rectangle beginning at (x,y) with the givenwidth andheight, using the brushstyle specified.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the givenrectangle with the brushstyle specified.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the givenrectangle with the brushstyle specified.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the givenrectangle with the specifiedbrush.
This is an overloaded function.
Fills the givenrectangle with thecolor specified.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the givenrectangle with thecolor specified.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the rectangle beginning at (x,y) with the givenwidth andheight, using the givenbrush.
This is an overloaded function.
Fills the rectangle beginning at (x,y) with the givenwidth andheight, using the givencolor.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the rectangle beginning at (x,y) with the givenwidth andheight, using the givencolor.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the givenrectangle with the specifiedcolor.
This function was introduced in Qt 4.5.
This is an overloaded function.
Fills the givenrectangle with the specifiedcolor.
This function was introduced in Qt 4.5.
Returns the currently set font used for drawing text.
See alsosetFont(),drawText(), andSettings.
Returns the font info for the painter if the painter is active. Otherwise, the return value is undefined.
See alsofont(),isActive(), andSettings.
Returns the font metrics for the painter if the painter is active. Otherwise, the return value is undefined.
See alsofont(),isActive(), andSettings.
Returns true if clipping has been set; otherwise returns false.
See alsosetClipping() andClipping.
Initializes the painters pen, background and font to the same as the givenwidget. This function is called automatically when the painter is opened on aQWidget.
Returns true ifbegin() has been called andend() has not yet been called; otherwise returns false.
See alsobegin() andQPaintDevice::paintingActive().
Returns the layout direction used by the painter when drawing text.
See alsoQTextOption::textDirection(),setLayoutDirection(),drawText(), andSettings.
Returns the opacity of the painter. The default value is 1.
This function was introduced in Qt 4.2.
See alsosetOpacity().
Returns the paint engine that the painter is currently operating on if the painter is active; otherwise 0.
See alsoisActive().
Returns the painter's current pen.
Returns a flag that specifies the rendering hints that are set for this painter.
See alsosetRenderHints(),testRenderHint(), andRendering Quality.
Resets any transformations that were made usingtranslate(),scale(),shear(),rotate(),setWorldTransform(),setViewport() andsetWindow().
See alsoCoordinate Transformations.
Restores the current painter state (pops a saved state off the stack).
See alsosave().
Rotates the coordinate system the givenangle clockwise.
See alsosetWorldTransform() andCoordinate Transformations.
Saves the current painter state (pushes the state onto a stack). A save() must be followed by a correspondingrestore(); theend() function unwinds the stack.
See alsorestore().
Scales the coordinate system by (sx,sy).
See alsosetWorldTransform() andCoordinate Transformations.
Sets the background brush of the painter to the givenbrush.
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 alsobackground(),setBackgroundMode(), andSettings.
Sets the background mode of the painter to the givenmode
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 useQPixmap::setMask().
See alsobackgroundMode(),setBackground(), andSettings.
Sets the painter's brush to the givenbrush.
The painter's brush defines how shapes are filled.
This is an overloaded function.
Sets the painter's brush to black color and the specifiedstyle.
Sets the brush origin toposition.
The brush origin specifies the (0, 0) coordinate of the painter's brush.
Note that while thebrushOrigin() 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'sautoFillBackground property to true.
See alsobrushOrigin() andSettings.
This is an overloaded function.
Sets the brush's origin to the givenposition.
This is an overloaded function.
Sets the brush's origin to point (x,y).
Enables clipping, and sets the clip path for the painter to the givenpath, with the clipoperation.
Note that the clip path is specified in logical (painter) coordinates.
See alsoclipPath(),clipRegion(), andClipping.
Enables clipping, and sets the clip region to the givenrectangle using the given clipoperation. The default operation is to replace the current clip rectangle.
Note that the clip rectangle is specified in logical (painter) coordinates.
See alsoclipRegion(),setClipping(), andClipping.
Enables clipping, and sets the clip region to the rectangle beginning at (x,y) with the givenwidth andheight.
This is an overloaded function.
Enables clipping, and sets the clip region to the givenrectangle using the given clipoperation.
Sets the clip region to the givenregion using the specified clipoperation. The default clip operation is to replace the current clip region.
Note that the clip region is given in logical coordinates.
See alsoclipRegion(),setClipRect(), andClipping.
Enables clipping ifenable is true, or disables clipping ifenable is false.
See alsohasClipping() andClipping.
Sets the composition mode to the givenmode.
Warning: Only aQPainter operating on aQImage fully supports all composition modes. The RasterOp modes are supported for X11 as described incompositionMode().
See alsocompositionMode().
Sets the painter's font to the givenfont.
This font is used by subsequentdrawText() 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() andfontInfo() returns the font actually being used (which may be the same).
See alsofont(),drawText(), andSettings.
Sets the layout direction used by the painter when drawing text, to the specifieddirection.
The default isQt::LayoutDirectionAuto, which will implicitly determine the direction from the text drawn.
See alsoQTextOption::setTextDirection(),layoutDirection(),drawText(), andSettings.
Sets the opacity of the painter toopacity. 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 alsoopacity().
Sets the painter's pen to be the givenpen.
Thepen defines how to draw lines and outlines, and it also defines the text color.
This is an overloaded function.
Sets the painter's pen to have styleQt::SolidLine, width 0 and the specifiedcolor.
This is an overloaded function.
Sets the painter's pen to have the givenstyle, width 0 and black color.
Sets the given renderhint on the painter ifon is true; otherwise clears the render hint.
See alsosetRenderHints(),renderHints(), andRendering Quality.
Sets the given renderhints on the painter ifon is true; otherwise clears the render hints.
This function was introduced in Qt 4.2.
See alsosetRenderHint(),renderHints(), andRendering Quality.
Sets the world transformation matrix. Ifcombine is true, the specifiedtransform is combined with the current matrix; otherwise it replaces the current matrix.
This function was introduced in Qt 4.3.
See alsotransform() andsetWorldTransform().
Enables view transformations ifenable is true, or disables view transformations ifenable is false.
See alsoviewTransformEnabled() andWindow-Viewport Conversion.
Sets the painter's viewport rectangle to the givenrectangle, and enables view transformations.
The viewport rectangle is part of the view transformation. The viewport specifies the device coordinate system. Its sister, thewindow(), specifies the logical coordinate system.
The default viewport rectangle is the same as the device's rectangle.
See alsoviewport(),viewTransformEnabled(), andWindow-Viewport Conversion.
This is an overloaded function.
Sets the painter's viewport rectangle to be the rectangle beginning at (x,y) with the givenwidth andheight.
Sets the painter's window to the givenrectangle, and enables view transformations.
The window rectangle is part of the view transformation. The window specifies the logical coordinate system. Its sister, theviewport(), specifies the device coordinate system.
The default window rectangle is the same as the device's rectangle.
See alsowindow(),viewTransformEnabled(), andWindow-Viewport Conversion.
This is an overloaded function.
Sets the painter's window to the rectangle beginning at (x,y) and the givenwidth andheight.
Enables transformations ifenable is true, or disables transformations ifenable is false. The world transformation matrix is not changed.
This function was introduced in Qt 4.2.
See alsoworldMatrixEnabled(),worldTransform(), andCoordinate Transformations.
Sets the world transformation matrix. Ifcombine is true, the specifiedmatrix is combined with the current matrix; otherwise it replaces the current matrix.
See alsoworldTransform(),transform(), andsetTransform().
Shears the coordinate system by (sh,sv).
See alsosetWorldTransform() andCoordinate Transformations.
Draws the outline (strokes) the pathpath with the pen specified bypen
See alsofillPath() andDrawing.
Returns true ifhint is set; otherwise returns false.
This function was introduced in Qt 4.3.
See alsorenderHints() andsetRenderHint().
Returns the world transformation matrix.
See alsosetTransform() andworldTransform().
Translates the coordinate system by the givenoffset; i.e. the givenoffset is added to points.
See alsosetWorldTransform() andCoordinate Transformations.
This is an overloaded function.
Translates the coordinate system by the givenoffset.
This is an overloaded function.
Translates the coordinate system by the vector (dx,dy).
Returns true if view transformation is enabled; otherwise returns false.
See alsosetViewTransformEnabled() andworldTransform().
Returns the viewport rectangle.
See alsosetViewport() andsetViewTransformEnabled().
Returns the window rectangle.
See alsosetWindow() andsetViewTransformEnabled().
Returns true if world transformation is enabled; otherwise returns false.
This function was introduced in Qt 4.2.
See alsosetWorldMatrixEnabled(),worldTransform(), andCoordinate System.
Returns the world transformation matrix.
See alsosetWorldTransform().
© 2016 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of theGNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.