|  | Home · All Classes · Main Classes · Annotated · Grouped Classes · Functions |

# QPaintEngine Class Reference

The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a given platform. More...

    #include <QPaintEngine>

Part of the QtGui module.

- List of all members, including inherited members

### Public Types

- enum PaintEngineFeature { CoordTransform, PenWidthTransform, PatternTransform, PixmapTransform, ..., FillAntialiasing }
- flags PaintEngineFeatures
- enum PolygonDrawMode { OddEvenMode, WindingMode, ConvexMode, PolylineMode }
- enum Type { X11, Windows, Gdiplus, QuickDraw, ..., MaxUser }

### Public Functions

- QPaintEngine ( PaintEngineFeatures caps = 0 )
- virtual ~QPaintEngine ()
- virtual bool begin ( QPaintDevice * pdev ) = 0
- virtual void drawEllipse ( const QRectF & rect )
- virtual void drawImage ( const QRectF & rectangle, const QImage & image, const QRectF & sr, Qt::ImageConversionFlags flags = Qt::AutoColor )
- virtual void drawLine ( const QLineF & line )
- virtual void drawLines ( const QLineF * lines, int lineCount )
- virtual void drawPath ( const QPainterPath & path )
- virtual void drawPixmap ( const QRectF & r, const QPixmap & pm, const QRectF & sr, Qt::PixmapDrawingMode mode = Qt::ComposePixmap ) = 0
- virtual void drawPoint ( const QPointF & pf )
- virtual void drawPoints ( const QPointF * points, int pointCount )
- virtual void drawPolygon ( const QPointF * points, int pointCount, PolygonDrawMode mode )
- virtual void drawPolygon ( const QPoint * points, int pointCount, PolygonDrawMode mode )
- virtual void drawRect ( const QRectF & rf )
- virtual void drawRects ( const QRectF * rects, int rectCount )
- virtual void drawTextItem ( const QPointF & p, const QTextItem & textItem )
- virtual void drawTiledPixmap ( const QRectF & rect, const QPixmap & pixmap, const QPointF & p, Qt::PixmapDrawingMode mode = Qt::ComposePixmap )
- virtual bool end () = 0
- bool hasFeature ( PaintEngineFeatures feature ) const
- bool isActive () const
- QPaintDevice * paintDevice () const
- QPainter * painter () const
- QPainter::RenderHints renderHints () const
- void setActive ( bool state )
- void setRenderHint ( QPainter::RenderHint hint, bool on )
- virtual QPainter::RenderHints supportedRenderHints () const
- virtual Type type () const = 0
- virtual void updateBackground ( Qt::BGMode bgmode, const QBrush & brush ) = 0
- virtual void updateBrush ( const QBrush & brush, const QPointF & origin ) = 0
- virtual void updateClipPath ( const QPainterPath & path, Qt::ClipOperation op )
- virtual void updateClipRegion ( const QRegion & region, Qt::ClipOperation op ) = 0
- virtual void updateFont ( const QFont & f ) = 0
- virtual void updateMatrix ( const QMatrix & matrix ) = 0
- virtual void updatePen ( const QPen & pen ) = 0
- virtual void updateRenderHints ( QPainter::RenderHints hints )

## Detailed Description

The QPaintEngine class provides an abstract definition of how QPainter draws to a given device on a given platform.

Qt 4.0 provides several premade implementations of QPaintEngine for the different painter backends we support. We provide one paint engine for each window system and painting framework we support. This includes X11 on Unix/Linux, GDI/GDI+ on Windows and QuickDraw/CoreGraphics on Mac OS X. In addition we provide QPaintEngine implementations for OpenGL (accessible through QGLWidget) and PostScript (accessible through QPSPrinter on X11).

If one wants to use QPainter to draw to a different backend, such as PDF, one must subclass QPaintEngine and reimplement all its virtual functions. The QPaintEngine implementation is then made available by subclassing QPaintDevice and reimplementing the virtual function `QPaintDevice::paintEngine()`.

QPaintEngine is created and owned by the QPaintDevice that created it.

The big advantage of the QPaintEngine approach opposed to the previous QPainter/QPaintDevice::cmd() approach is that it is now possible to adapt to multiple technologies on each platform and take advantage of the to the fullest.

See also QPainter and QPaintDevice::paintEngine().

## Member Type Documentation

### enum QPaintEngine::PaintEngineFeature
flags QPaintEngine::PaintEngineFeatures

This enum is used to describe the features or capabilities that the paint engine has. If a feature is not supported by the engine, QPainter will do a best effort to emulate that feature through other means. The features that are currently emulated are: `CoordTransform`, `PixmapTransform`, `LinearGradientFill`, `PixmapScale`, `AlphaFill` and `ClipTransform`.

Constant | Value | Description
--- | --- | ---
`QPaintEngine::CoordTransform` | `0x000001` | The engine can transform the points in a drawing operation.
`QPaintEngine::PenWidthTransform` | `0x000002` | The engine has support for transforming pen widths.
`QPaintEngine::PatternTransform` | `0x000004` | The engine has support for transforming brush patterns.
`QPaintEngine::PixmapTransform` | `0x000010` | The engine can transform pixmaps, including rotation and shearing.
`QPaintEngine::LinearGradientFill` | `0x000020` | The engine can fill with linear gradients
`QPaintEngine::LinearGradientFillPolygon` | `0x000040` | The engine is capable of gradient fills in polygons only. Engines that support this feature and not regular gradient filling will have all primitives converted to polygons first so that this feature can be used instead.
`QPaintEngine::PixmapScale` | `0x000080` | The engine can scale pixmaps.
`QPaintEngine::AlphaPixmap` | `0x000800` | The engine can draw alpha pixmaps.
`QPaintEngine::AlphaFill` | `0x000100` | The engine can fill with alpha colors. If this feature is not specified, alpha filling can be emulated using alpha pixmaps.
`QPaintEngine::AlphaFillPolygon` | `0x000200` | The engine can fill polygons with alpha colors. Engines that specify this feature and not AlphaFill will have all primitives converted to polygons first, so that this feature can be used instead.
`QPaintEngine::AlphaStroke` | `0x000400` | The engine can draw outlines with alpha colors. Engines that do not support alphastroke can emulate it using AlphaFill, AlphaFillPolygon or AlphaPixmap.
`QPaintEngine::PainterPaths` | `0x001000` | The engine has path support.
`QPaintEngine::ClipTransform` | `0x002000` | The engine is capable of transforming clip regions.
`QPaintEngine::PaintOutsidePaintEvent` | `0x20000000` | The engine is capable of painting outside of paint events.
`QPaintEngine::PatternBrush` | `0x000008` | The engine is capable of rendering brushes with the brush patterns specified in Qt::BrushStyle.
`QPaintEngine::LineAntialiasing` | `0x004000` | The engine is capable of line antialiasing.
`QPaintEngine::FillAntialiasing` | `0x008000` | The engine is capable of fill antialiasing. If an engine is capable of fill, but not line antialiasing, line antialiasing will be emulated using a filled polygon that has the shape of the line.

The `PaintEngineFeatures` type stores an OR combination of `PaintEngineFeature` values.

### enum QPaintEngine::PolygonDrawMode

Constant | Value | Description
--- | --- | ---
`QPaintEngine::OddEvenMode` | `0` | The polygon should be drawn using OddEven fill rule.
`QPaintEngine::WindingMode` | `1` | The polygon should be drawn using Winding fill rule.
`QPaintEngine::ConvexMode` | `2` | The polygon is a convex polygon and can be drawn using specialized algorithms where available.
`QPaintEngine::PolylineMode` | `3` | Only the outline of the polygon should be drawn.

### enum QPaintEngine::Type

Constant | Value | Description
--- | --- | ---
`QPaintEngine::X11` | `0` |
`QPaintEngine::Windows` | `1` |
`QPaintEngine::Gdiplus` |  | (same as Windows)
`QPaintEngine::QuickDraw` | `2` | (same as CoreGraphics)
`QPaintEngine::MacPrinter` | `4` |
`QPaintEngine::CoreGraphics` | `3` | Mac OS X
`QPaintEngine::QWindowSystem` | `5` | Qt/Embedded
`QPaintEngine::PostScript` | `6` |
`QPaintEngine::OpenGL` | `7` |
`QPaintEngine::Picture` | `8` | QPicture format
`QPaintEngine::SVG` | `9` | Scalable Vector Graphics XML format
`QPaintEngine::User` | `50` | First user type ID
`QPaintEngine::MaxUser` | `100` | Last user type ID

## Member Function Documentation

### QPaintEngine::QPaintEngine ( PaintEngineFeatures caps = 0 )

Creates a paint engine with the featureset specified by caps.

### QPaintEngine::~QPaintEngine () `[virtual]`

Destroys the paint engine.

### bool QPaintEngine::begin ( QPaintDevice * pdev ) `[pure virtual]`

Reimplement this function to initialise your paint engine when painting is to start on the paint device pdev. Return true if the initialization was successful; otherwise return false.

See also end() and isActive().

### void QPaintEngine::drawEllipse ( const QRectF & rect ) `[virtual]`

Reimplement this function to draw the largest ellipse that can be contained within rectangle rect.

The default implementation calls drawPolygon().

See also drawPolygon.

### void QPaintEngine::drawImage ( const QRectF & rectangle, const QImage & image, const QRectF & sr, Qt::ImageConversionFlags flags = Qt::AutoColor ) `[virtual]`

Reimplement this function to draw the part of the image specified by the sr rectangle in the given rectangle using the given conversion flags flags, to convert it to a pixmap.

### void QPaintEngine::drawLine ( const QLineF & line ) `[virtual]`

The default implementation splits line into two points and calls the integer version of drawLine().

### void QPaintEngine::drawLines ( const QLineF * lines, int lineCount ) `[virtual]`

Draws the first lineCount lines in the buffer lines

### void QPaintEngine::drawPath ( const QPainterPath & path ) `[virtual]`

The default implementation ignores the path and does nothing.

### void QPaintEngine::drawPixmap ( const QRectF & r, const QPixmap & pm, const QRectF & sr, Qt::PixmapDrawingMode mode = Qt::ComposePixmap ) `[pure virtual]`

Reimplement this function to draw the part of the pm specified by the sr rectangle in the given r using the given drawing mode.

### void QPaintEngine::drawPoint ( const QPointF & pf ) `[virtual]`

The default implementation converts pf to an integer point and calls the integer version of drawPoint().

### void QPaintEngine::drawPoints ( const QPointF * points, int pointCount ) `[virtual]`

Draws the first pointCount points in the buffer points

### void QPaintEngine::drawPolygon ( const QPointF * points, int pointCount, PolygonDrawMode mode ) `[virtual]`

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

The default implementation of this function will try to use drawPath if the engine supports the feature QPaintEngine::PainterPaths or try the int based drawPolygon() implementation if not.

### void QPaintEngine::drawPolygon ( const QPoint * points, int pointCount, PolygonDrawMode mode ) `[virtual]`

This is an overloaded member function, provided for convenience. It behaves essentially like the above function.

Reimplement this virtual function to draw the polygon defined by the pointCount first points in points, using mode mode.

The default implementation of this function will try to use drawPath() if the engine supports the feature QPaintEngine::PainterPaths or try the float based drawPolygon() implementation if not.

### void QPaintEngine::drawRect ( const QRectF & rf ) `[virtual]`

The default implementation converts rf to an integer rectangle and calls the integer version of drawRect().

### void QPaintEngine::drawRects ( const QRectF * rects, int rectCount ) `[virtual]`

Draws the first rectCount rectangles in the buffer rects.

### void QPaintEngine::drawTextItem ( const QPointF & p, const QTextItem & textItem ) `[virtual]`

This function draws the text item textItem at position p. The default implementation of this function converts the text to a QPainterPath and paints the resulting path.

### void QPaintEngine::drawTiledPixmap ( const QRectF & rect, const QPixmap & pixmap, const QPointF & p, Qt::PixmapDrawingMode mode = Qt::ComposePixmap ) `[virtual]`

Reimplement this function to draw the pixmap in the given rect, starting at the given p. The pixmap will be drawn repeatedly until the rect is filled using the given mode.

### bool QPaintEngine::end () `[pure virtual]`

Reimplement this function to finish painting on the current paint device. Return true if painting was finished successfully; otherwise return false.

See also begin() and isActive().

### bool QPaintEngine::hasFeature ( PaintEngineFeatures feature ) const

Returns true if the paint engine supports the specified feature; otherwise returns false.

### bool QPaintEngine::isActive () const

Returns true if the paint engine is actively drawing; otherwise returns false.

See also setActive().

### QPaintDevice * QPaintEngine::paintDevice () const

Returns the engine that this engine is painting on, if painting is active; otherwise returns 0.

### QPainter * QPaintEngine::painter () const

Returns the paint engine's painter.

### QPainter::RenderHints QPaintEngine::renderHints () const

Returns the currently set renderhints.

### void QPaintEngine::setActive ( bool state )

Sets the active state of the paint engine to state.

See also isActive().

### void QPaintEngine::setRenderHint ( QPainter::RenderHint hint, bool on )

Sets the render hint hint on this engine if on is true; otherwise clears the render hint.

### QPainter::RenderHints QPaintEngine::supportedRenderHints () const `[virtual]`

Returns the set of supported renderhints.

### Type QPaintEngine::type () const `[pure virtual]`

Reimplement this function to return the paint engine Type.

### void QPaintEngine::updateBackground ( Qt::BGMode bgmode, const QBrush & brush ) `[pure virtual]`

This function is called when the engine needs to be updated with new background settings. bgmode describes the background mode and brush describes the background brush.

### void QPaintEngine::updateBrush ( const QBrush & brush, const QPointF & origin ) `[pure virtual]`

This function is called when the engine needs to be updated with a new brush, specified with brush. origin describes the brush origin.

If the brush is a gradient brush, the gradient points are specified in device coordinates.

### void QPaintEngine::updateClipPath ( const QPainterPath & path, Qt::ClipOperation op ) `[virtual]`

This function is called when the engine needs to be updated with the new clip path. The value of op specifies how the clip path should be combined with the current clip.

### void QPaintEngine::updateClipRegion ( const QRegion & region, Qt::ClipOperation op ) `[pure virtual]`

This function is called when the clip region changes. The clip operation op specifies how the new region region should be combined (if at all) with the new region.

### void QPaintEngine::updateFont ( const QFont & f ) `[pure virtual]`

This function is called when the engine needs to be updated with a new font, specified by f

### void QPaintEngine::updateMatrix ( const QMatrix & matrix ) `[pure virtual]`

This function is called when the engine needs to be updated with new transformation settings, specified with matrix.

### void QPaintEngine::updatePen ( const QPen & pen ) `[pure virtual]`

This function is called when the engine needs to be updated with the a new pen, specified by pen.

### void QPaintEngine::updateRenderHints ( QPainter::RenderHints hints ) `[virtual]`

This function is caleed when the engine needs to be updated with the new set of renderhints specified by hints.