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

# QPainterPath Class Reference

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

    #include <QPainterPath>

- List of all members, including inherited members

### Public Types

- enum FillMode { OddEven, Winding }

### Public Functions

- QPainterPath ()
- QPainterPath ( const QPointF & startPoint )
- QPainterPath ( const QPainterPath & other )
- ~QPainterPath ()
- void addEllipse ( const QRectF & boundingRect )
- void addEllipse ( float x, float y, float width, float height )
- void addPath ( const QPainterPath & other )
- void addPolygon ( const QPolygon & polygon )
- void addRect ( const QRectF & rectangle )
- void addRect ( float x, float y, float width, float height )
- void addText ( const QPointF & point, const QFont & font, const QString & text )
- void addText ( float x, float y, const QFont & font, const QString & text )
- void arcTo ( const QRectF & rectangle, float startAngle, float sweepLength )
- void arcTo ( float x, float y, float width, float height, float startAngle, float sweepLength )
- QRectF boundingRect () const
- void closeSubpath ()
- void curveTo ( const QPointF & c1, const QPointF & c2, const QPointF & endPoint )
- void curveTo ( float ctrlPt1x, float ctrlPt1y, float ctrlPt2x, float ctrlPt2y, float endPtx, float endPty )
- const QPainterPath::Element & elementAt ( int index ) const
- int elementCount () const
- FillMode fillMode () const
- bool isEmpty () const
- void lineTo ( const QPointF & endPoint )
- void lineTo ( float x, float y )
- void moveTo ( const QPointF & point )
- void moveTo ( float x, float y )
- void setFillMode ( FillMode fillMode )
- QPolygon toFillPolygon () const
- QList<QPolygon> toFillPolygons () const
- QPainterPath toReversed () const
- QList<QPolygon> toSubpathPolygons () const
- QPainterPath & operator+= ( const QPainterPath & other )
- QPainterPath & operator= ( const QPainterPath & other )

## Detailed Description

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

A painter path is an object composed of a number of graphical building blocks, such as rectangles, ellipses, lines, and curves. A painter path can be used for filling, outlining, and clipping. The main advantage of painter paths over normal drawing operations is that complex shapes only need to be created once, but they can be drawn many times using only calls to QPainter::drawPath().

Building blocks can be joined in closed subpaths, such as a rectangle or an ellipse, or they can exist independently as unclosed subpaths. Note that unclosed paths will not be filled.

Below is a code snippet that shows how a path can be used. The painter in this case has a pen width of 3 and a light blue brush. The painter path is initially empty when constructed. We first add a rectangle, which becomes a closed subpath. We then add two bezier curves, and finally draw the entire path.

        QPainterPath path;
        path.addRect(20, 20, 80, 80);

        path.moveTo(0, 0);
        path.curveTo(99, 0,  50, 50,  99, 99);
        path.curveTo(0, 99,  50, 50,  0, 0);

        painter.drawPath(path);

See also QPainter.

## Member Type Documentation

### enum QPainterPath::FillMode

Specifies which method should be used to fill the path.

`QPainterPath::OddEven` | Specifies that the region is filled using the odd even fill rule. With this rule, one determines wheter a point is inside the path as follows: Draw a horizontal line from the point to outside the path and count the number of intersections. If the number of intersections is an odd number the point is inside the path. This mode is the default.
`QPainterPath::Winding` | Specifies that the region is filled using the non zero winding rule. With this rule, one determines wheter a point is inside the path as follows: Draw a horizontal line from the path to the outside of the path. Determine the direction of the path in each intersection point, up or down. The winding number is determined by summing the direction of each intersection. If the number is non zero, the point is inside the path. This fill mode can also in most cases be considered as the intersection of closed shapes.

## Member Function Documentation

### QPainterPath::QPainterPath ()

Constructs a new empty QPainterPath.

### QPainterPath::QPainterPath ( const QPointF & startPoint )

Creates a new painter path with startPoint as starting poing

### QPainterPath::QPainterPath ( const QPainterPath & other )

Creates a new painter path that is a copy of the other painter path.

### QPainterPath::~QPainterPath ()

Destroys the painter path.

### void QPainterPath::addEllipse ( const QRectF & boundingRect )

Creates an ellipse within the bounding rectangle specified by boundingRect and adds it to the painter path.

If the current subpath is closed, a new subpath is started. The ellipse is clockwise starting and starting zero degrees.

### void QPainterPath::addEllipse ( float x, float y, float width, float height )

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

Creates an ellipse within a bounding rectangle defined by its top-left corner at (x, y), width and height, and adds it to the painter path.

If the current subpath is closed, a new subpath is started. The ellipse is clockwise starting and starting zero degrees.

### void QPainterPath::addPath ( const QPainterPath & other )

Adds the path other to this path. If the current subpath is path is unclosed, other is joined with it.

### void QPainterPath::addPolygon ( const QPolygon & polygon )

Adds the polygon to path as a new subpath. If the current subpath is closed, a new subpath is started at the polygons first point.

### void QPainterPath::addRect ( const QRectF & rectangle )

Adds the rectangle to this path as a closed subpath. The rectangle is added as a clockwise set of lines. An empty subpath with current position at (0, 0) is in use after this function returns. The rectangle is oriented clockwise starting at topleft.

### void QPainterPath::addRect ( float x, float y, float width, float height )

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

Adds a rectangle at position (x, y), with the given width and height. The rectangle is added as a clockwise set of lines. An empty subpath with current position at (0, 0) is in use after this function returns.

### void QPainterPath::addText ( const QPointF & point, const QFont & font, const QString & text )

Adds the given text to this path as a set of closed subpaths created from the font supplied. The subpaths are positioned so that the left end of the text's baseline lies at the point specified.

See also QPainter::drawText.

### void QPainterPath::addText ( float x, float y, const QFont & font, const QString & text )

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

Adds the given text to this path as a set of closed subpaths created from the font supplied. The subpaths are positioned so that the left end of the text's baseline lies at the point specified by (x, y).

See also QPainter::drawText.

### void QPainterPath::arcTo ( const QRectF & rectangle, float startAngle, float sweepLength )

Creates an arc that occupies the given rectangle, beginning at startAngle and extending sweepLength degrees anti-clockwise. Angles are specified in degrees. This function connects the current point to the starting point of the arc if they are not already connected.

See also QPainter::drawArc.

### void QPainterPath::arcTo ( float x, float y, float width, float height, float startAngle, float sweepLength )

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

The arc's lies within the rectangle given by the point (x, y), width and height, beginning at startAngle and extending sweepLength degrees anti-clockwise. Angles are specified in degrees. This function connects the current point to the starting point of the arc if they are not already connected.

See also QPainter::drawArc.

### QRectF QPainterPath::boundingRect () const

Returns the bounding rectangle of this painter path as a rectangle with floating point precision.

### void QPainterPath::closeSubpath ()

Closes the current subpath. If the subpath does not contain any elements, the function does nothing. A new subpath is automatically begun when the current subpath is closed. The current point of the new path is (0, 0).

### void QPainterPath::curveTo ( const QPointF & c1, const QPointF & c2, const QPointF & endPoint )

Adds a Bezier curve between the current point and endPoint with control points specified by c1, and c2. After the curve is added, the current point is updated to be at the end point of the curve.

### void QPainterPath::curveTo ( float ctrlPt1x, float ctrlPt1y, float ctrlPt2x, float ctrlPt2y, float endPtx, float endPty )

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

Adds a Bezier curve between the current point and the endpoint (endPtx, endPty) with control points specified by (ctrlPt1x, ctrlPt1y) and (ctrlPt2x, ctrlPt2y). After the curve is added, the current point is updated to be at the end point of the curve.

### const QPainterPath::Element & QPainterPath::elementAt ( int index ) const

Returns the element at the given index in the painter path.

### int QPainterPath::elementCount () const

Returns the number of path elements in the painter path.

### FillMode QPainterPath::fillMode () const

Returns the fill mode of the painter path. The default fill mode is OddEven.

See also FillMode and setFillMode().

### bool QPainterPath::isEmpty () const

Returns true if there are no elements in this path.

### void QPainterPath::lineTo ( const QPointF & endPoint )

Adds a straight line from the current point to the given endPoint. After the line is drawn, the current point is updated to be at the end point of the line.

### void QPainterPath::lineTo ( float x, float y )

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

Draws a line from the current point to the point at (x, y). After the line is drawn, the current point is updated to be at the end point of the line.

### void QPainterPath::moveTo ( const QPointF & point )

Moves the current point to the given point. Moving the current point will also start a new subpath. The previously current path will not be closed implicitly before the new one is started.

### void QPainterPath::moveTo ( float x, float y )

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

Moves the current point to (x, y). Moving the current point will also start a new subpath. The previously current path will not be closed implicitly before the new one is started.

### void QPainterPath::setFillMode ( FillMode fillMode )

Sets the fill mode of the painter path to fillMode.

See also FillMode and fillMode.

### QPolygon QPainterPath::toFillPolygon () const

Returns the painter path as a filled polygon.

### QList<QPolygon> QPainterPath::toFillPolygons () const

Creates a polygon from the path.

### QPainterPath QPainterPath::toReversed () const

Creates a reversed copy of this path and returns it

### QList<QPolygon> QPainterPath::toSubpathPolygons () const

Returns a list of polygons corresponding to the subpaths in the painter path.

### QPainterPath & QPainterPath::operator+= ( const QPainterPath & other )

Appends the other painter path to this painter path and returns a reference to the result.

### QPainterPath & QPainterPath::operator= ( const QPainterPath & other )

Assigns the other painter path to this painter path.