Qt
Internal/Contributor docs for the Qt SDK. Note: These are NOT official API docs; those are found at https://doc.qt.io/
Loading...
Searching...
No Matches
QPainterPath Class Reference

\inmodule QtGui More...

#include <qpainterpath.h>

Collaboration diagram for QPainterPath:

Classes

class  Element
 \inmodule QtGui More...

Public Types

enum  ElementType { MoveToElement , LineToElement , CurveToElement , CurveToDataElement }
 This enum describes the types of elements used to connect vertices in subpaths. More...

Public Member Functions

 QPainterPath () noexcept
 Constructs an empty QPainterPath object.
 QPainterPath (const QPointF &startPoint)
 Creates a QPainterPath object with the given startPoint as its current position.
 QPainterPath (const QPainterPath &other)
 Creates a QPainterPath object that is a copy of the given path.
QPainterPathoperator= (const QPainterPath &other)
 Assigns the given path to this painter path.
 QPainterPath (QPainterPath &&other) noexcept
 ~QPainterPath ()
 Destroys this QPainterPath object.
void swap (QPainterPath &other) noexcept
void clear ()
 Clears the path elements stored.
void reserve (int size)
 Reserves a given amount of elements in QPainterPath's internal memory.
int capacity () const
 Returns the number of elements allocated by the QPainterPath.
void closeSubpath ()
 Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path.
void moveTo (const QPointF &p)
 Moves the current point to the given point, implicitly starting a new subpath and closing the previous one.
void moveTo (qreal x, qreal y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the current position to ({x}, {y}) and starts a new subpath, implicitly closing the previous path.
void lineTo (const QPointF &p)
 Adds a straight line from the current position to the given endPoint.
void lineTo (qreal x, qreal y)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws a line from the current position to the point ({x}, {y}).
void arcMoveTo (const QRectF &rect, qreal angle)
void arcMoveTo (qreal x, qreal y, qreal w, qreal h, qreal angle)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
void arcTo (const QRectF &rect, qreal startAngle, qreal arcLength)
 Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending sweepLength degrees counter-clockwise.
void arcTo (qreal x, qreal y, qreal w, qreal h, qreal startAngle, qreal arcLength)
void cubicTo (const QPointF &ctrlPt1, const QPointF &ctrlPt2, const QPointF &endPt)
 Adds a cubic Bezier curve between the current position and the given endPoint using the control points specified by c1, and c2.
void cubicTo (qreal ctrlPt1x, qreal ctrlPt1y, qreal ctrlPt2x, qreal ctrlPt2y, qreal endPtx, qreal endPty)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds a cubic Bezier curve between the current position and the end point ({endPointX}, {endPointY}) with control points specified by ({c1X}, {c1Y}) and ({c2X}, {c2Y}).
void quadTo (const QPointF &ctrlPt, const QPointF &endPt)
 Adds a quadratic Bezier curve between the current position and the given endPoint with the control point specified by c.
void quadTo (qreal ctrlPtx, qreal ctrlPty, qreal endPtx, qreal endPty)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds a quadratic Bezier curve between the current point and the endpoint ({endPointX}, {endPointY}) with the control point specified by ({cx}, {cy}).
QPointF currentPosition () const
 Returns the current position of the path.
void addRect (const QRectF &rect)
 Adds the given rectangle to this path as a closed subpath.
void addRect (qreal x, qreal y, qreal w, qreal h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds a rectangle at position ({x}, {y}), with the given width and height, as a closed subpath.
void addEllipse (const QRectF &rect)
 Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed subpath.
void addEllipse (qreal x, qreal y, qreal w, qreal h)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates an ellipse within the bounding rectangle defined by its top-left corner at (x, y), width and height, and adds it to the painter path as a closed subpath.
void addEllipse (const QPointF &center, qreal rx, qreal ry)
void addPolygon (const QPolygonF &polygon)
 Adds the given polygon to the path as an (unclosed) subpath.
void addText (const QPointF &point, const QFont &f, const QString &text)
 Adds the given text to this path as a set of closed subpaths created from the font supplied.
void addText (qreal x, qreal y, const QFont &f, const QString &text)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds the given text to this path as a set of closed subpaths created from the font supplied.
void addPath (const QPainterPath &path)
 Adds the given path to this path as a closed subpath.
void addRegion (const QRegion &region)
 Adds the given region to the path by adding each rectangle in the region as a separate closed subpath.
void addRoundedRect (const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
void addRoundedRect (qreal x, qreal y, qreal w, qreal h, qreal xRadius, qreal yRadius, Qt::SizeMode mode=Qt::AbsoluteSize)
void connectPath (const QPainterPath &path)
 Connects the given path to this path by adding a line from the last element of this path to the first element of the given path.
bool contains (const QPointF &pt) const
 Returns true if the given point is inside the path, otherwise returns false.
bool contains (const QRectF &rect) const
 Returns true if the given rectangle is inside the path, otherwise returns false.
bool intersects (const QRectF &rect) const
 Returns true if any point in the given rectangle intersects the path; otherwise returns false.
void translate (qreal dx, qreal dy)
 Translates all elements in the path by ({dx}, {dy}).
void translate (const QPointF &offset)
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
QPainterPath translated (qreal dx, qreal dy) const
 Returns a copy of the path that is translated by ({dx}, {dy}).
QPainterPath translated (const QPointF &offset) const
 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.
QRectF boundingRect () const
 Returns the bounding rectangle of this painter path as a rectangle with floating point precision.
QRectF controlPointRect () const
 Returns the rectangle containing all the points and control points in this path.
Qt::FillRule fillRule () const
 Returns the painter path's currently set fill rule.
void setFillRule (Qt::FillRule fillRule)
 Sets the fill rule of the painter path to the given fillRule.
bool isEmpty () const
 Returns true if either there are no elements in this path, or if the only element is a MoveToElement; otherwise returns false.
QPainterPath toReversed () const
 Creates and returns a reversed copy of the path.
QList< QPolygonFtoSubpathPolygons (const QTransform &matrix=QTransform()) const
 Converts the path into a list of polygons using the QTransform matrix, and returns the list.
QList< QPolygonFtoFillPolygons (const QTransform &matrix=QTransform()) const
 Converts the path into a list of polygons using the QTransform matrix, and returns the list.
QPolygonF toFillPolygon (const QTransform &matrix=QTransform()) const
 Converts the path into a polygon using the QTransform matrix, and returns the polygon.
int elementCount () const
 Returns the number of path elements in the painter path.
QPainterPath::Element elementAt (int i) const
 Returns the element at the given index in the painter path.
void setElementPositionAt (int i, qreal x, qreal y)
bool isCachingEnabled () const
 Returns true if caching is enabled; otherwise returns false.
void setCachingEnabled (bool enabled)
 Enables or disables length caching according to the value of enabled.
qreal length () const
 Returns the length of the current path.
qreal percentAtLength (qreal len) const
 Returns percentage of the whole path at the specified length len.
QPointF pointAtPercent (qreal t) const
 Returns the point at at the percentage t of the current path.
qreal angleAtPercent (qreal t) const
 Returns the angle of the path tangent at the percentage t.
qreal slopeAtPercent (qreal t) const
 Returns the slope of the path at the percentage t.
QPainterPath trimmed (qreal fromFraction, qreal toFraction, qreal offset=0) const
bool intersects (const QPainterPath &p) const
bool contains (const QPainterPath &p) const
QPainterPath united (const QPainterPath &r) const
QPainterPath intersected (const QPainterPath &r) const
QPainterPath subtracted (const QPainterPath &r) const
QPainterPath simplified () const
bool operator== (const QPainterPath &other) const
 Returns true if this painterpath is equal to the given path.
bool operator!= (const QPainterPath &other) const
 Returns true if this painter path differs from the given path.
QPainterPath operator& (const QPainterPath &other) const
QPainterPath operator| (const QPainterPath &other) const
QPainterPath operator+ (const QPainterPath &other) const
QPainterPath operator- (const QPainterPath &other) const
QPainterPathoperator&= (const QPainterPath &other)
QPainterPathoperator|= (const QPainterPath &other)
QPainterPathoperator+= (const QPainterPath &other)
QPainterPathoperator-= (const QPainterPath &other)

Friends

class QPainterPathStroker
class QPainterPathStrokerPrivate
class QPainterPathPrivate
class QTransform
class QVectorPath
Q_GUI_EXPORT const QVectorPathqtVectorPathForPath (const QPainterPath &path)
Q_GUI_EXPORT QDataStreamoperator<< (QDataStream &s, const QPainterPath &p)
 Writes the given painter path to the given stream, and returns a reference to the stream.
Q_GUI_EXPORT QDataStreamoperator>> (QDataStream &s, QPainterPath &p)
 Reads a painter path from the given stream into the specified path, and returns a reference to the stream.

Detailed Description

\inmodule QtGui

\reentrant

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. Building blocks can be joined in closed subpaths, for example as a rectangle or an ellipse. A closed path has coinciding start and end points. Or they can exist independently as unclosed subpaths, such as lines and curves.

A QPainterPath object can be used for filling, outlining, and clipping. To generate fillable outlines for a given painter path, use the QPainterPathStroker class. The main advantage of painter paths over normal drawing operations is that complex shapes only need to be created once; then they can be drawn many times using only calls to the QPainter::drawPath() function.

QPainterPath provides a collection of functions that can be used to obtain information about the path and its elements. In addition it is possible to reverse the order of the elements using the toReversed() function. There are also several functions to convert this painter path object into a polygon representation.

Definition at line 26 of file qpainterpath.h.

Member Enumeration Documentation

◆ ElementType

This enum describes the types of elements used to connect vertices in subpaths.

Note that elements added as closed subpaths using the addEllipse(), addPath(), addPolygon(), addRect(), addRegion() and addText() convenience functions, is actually added to the path as a collection of separate elements using the moveTo(), lineTo() and cubicTo() functions.

\value MoveToElement A new subpath. See also moveTo(). \value LineToElement A line. See also lineTo(). \value CurveToElement A curve. See also cubicTo() and quadTo(). \value CurveToDataElement The extra data required to describe a curve in a CurveToElement element.

See also
elementAt(), elementCount()
Enumerator
MoveToElement 
LineToElement 
CurveToElement 
CurveToDataElement 

Definition at line 29 of file qpainterpath.h.

Constructor & Destructor Documentation

◆ QPainterPath() [1/4]

QPainterPath::QPainterPath ( )
noexcept

Constructs an empty QPainterPath object.

Definition at line 501 of file qpainterpath.cpp.

◆ QPainterPath() [2/4]

QPainterPath::QPainterPath ( const QPointF & startPoint)
explicit

Creates a QPainterPath object with the given startPoint as its current position.

Definition at line 532 of file qpainterpath.cpp.

◆ QPainterPath() [3/4]

QPainterPath::QPainterPath ( const QPainterPath & path)

Creates a QPainterPath object that is a copy of the given path.

See also
operator=()

Definition at line 513 of file qpainterpath.cpp.

◆ QPainterPath() [4/4]

QPainterPath::QPainterPath ( QPainterPath && other)
inlinenoexcept
Since
6.10

Move-constructs a new painter path from other.

The moved-from object other is placed in the default-constructed state.

Definition at line 57 of file qpainterpath.h.

◆ ~QPainterPath()

QPainterPath::~QPainterPath ( )

Destroys this QPainterPath object.

Definition at line 582 of file qpainterpath.cpp.

Member Function Documentation

◆ addEllipse() [1/3]

void QPainterPath::addEllipse ( const QPointF & center,
qreal rx,
qreal ry )
inline
Since
4.4

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Creates an ellipse positioned at {center} with radii {rx} and {ry}, and adds it to the painter path as a closed subpath.

Definition at line 276 of file qpainterpath.h.

◆ addEllipse() [2/3]

void QPainterPath::addEllipse ( const QRectF & boundingRectangle)

Creates an ellipse within the specified boundingRectangle and adds it to the painter path as a closed subpath.

The ellipse is composed of a clockwise curve, starting and finishing at zero degrees (the 3 o'clock position).

\table 100% \row

See also
arcTo(), QPainter::drawEllipse(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1104 of file qpainterpath.cpp.

◆ addEllipse() [3/3]

void QPainterPath::addEllipse ( qreal x,
qreal y,
qreal w,
qreal h )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Creates an ellipse within the bounding rectangle defined by its top-left corner at (x, y), width and height, and adds it to the painter path as a closed subpath.

Definition at line 271 of file qpainterpath.h.

◆ addPath()

void QPainterPath::addPath ( const QPainterPath & path)

Adds the given path to this path as a closed subpath.

See also
connectPath(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1230 of file qpainterpath.cpp.

◆ addPolygon()

void QPainterPath::addPolygon ( const QPolygonF & polygon)

Adds the given polygon to the path as an (unclosed) subpath.

Note that the current position after the polygon has been added, is the last point in polygon. To draw a line back to the first point, use the closeSubpath() function.

\table 100% \row

See also
lineTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1070 of file qpainterpath.cpp.

◆ addRect() [1/2]

void QPainterPath::addRect ( const QRectF & rectangle)

Adds the given rectangle to this path as a closed subpath.

The rectangle is added as a clockwise set of lines. The painter path's current position after the rectangle has been added is at the top-left corner of the rectangle.

\table 100% \row

See also
addRegion(), lineTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1024 of file qpainterpath.cpp.

◆ addRect() [2/2]

void QPainterPath::addRect ( qreal x,
qreal y,
qreal w,
qreal h )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds a rectangle at position ({x}, {y}), with the given width and height, as a closed subpath.

Definition at line 281 of file qpainterpath.h.

◆ addRegion()

void QPainterPath::addRegion ( const QRegion & region)

Adds the given region to the path by adding each rectangle in the region as a separate closed subpath.

See also
addRect(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1299 of file qpainterpath.cpp.

◆ addRoundedRect() [1/2]

void QPainterPath::addRoundedRect ( const QRectF & rect,
qreal xRadius,
qreal yRadius,
Qt::SizeMode mode = Qt::AbsoluteSize )
Since
4.4

Adds the given rectangle rect with rounded corners to the path.

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

See also
addRect()

Definition at line 3386 of file qpainterpath.cpp.

◆ addRoundedRect() [2/2]

void QPainterPath::addRoundedRect ( qreal x,
qreal y,
qreal w,
qreal h,
qreal xRadius,
qreal yRadius,
Qt::SizeMode mode = Qt::AbsoluteSize )
inline
Since
4.4 This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Adds the given rectangle x, y, w, h with rounded corners to the path.

Definition at line 286 of file qpainterpath.h.

◆ addText() [1/2]

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 specified point.

Some fonts may yield overlapping subpaths and will require the Qt::WindingFill fill rule for correct rendering.

\table 100% \row

See also
QPainter::drawText(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}, setFillRule()

Definition at line 1156 of file qpainterpath.cpp.

◆ addText() [2/2]

void QPainterPath::addText ( qreal x,
qreal y,
const QFont & font,
const QString & text )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.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).

Definition at line 293 of file qpainterpath.h.

◆ angleAtPercent()

qreal QPainterPath::angleAtPercent ( qreal t) const

Returns the angle of the path tangent at the percentage t.

The argument t has to be between 0 and 1.

Positive values for the angles mean counter-clockwise while negative values mean the clockwise direction. Zero degrees is at the 3 o'clock position.

Note that similarly to the other percent methods, the percentage measurement is not linear with regards to the length if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 3137 of file qpainterpath.cpp.

◆ arcMoveTo() [1/2]

void QPainterPath::arcMoveTo ( const QRectF & rectangle,
qreal angle )
Since
4.2

Creates a move to that lies on the arc that occupies the given rectangle at angle.

Angles are specified in degrees. Clockwise arcs can be specified using negative angles.

See also
moveTo(), arcTo()

Definition at line 971 of file qpainterpath.cpp.

◆ arcMoveTo() [2/2]

void QPainterPath::arcMoveTo ( qreal x,
qreal y,
qreal width,
qreal height,
qreal angle )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.2

Creates a move to that lies on the arc that occupies the QRectF(x, y, width, height) at angle.

Definition at line 254 of file qpainterpath.h.

◆ arcTo() [1/2]

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

Creates an arc that occupies the given rectangle, beginning at the specified startAngle and extending sweepLength degrees counter-clockwise.

Angles are specified in degrees. Clockwise arcs can be specified using negative angles.

Note that this function connects the starting point of the arc to the current position if they are not already connected. After the arc has been added, the current position is the last point in arc. To draw a line back to the first point, use the closeSubpath() function.

\table 100% \row

See also
arcMoveTo(), addEllipse(), QPainter::drawArc(), QPainter::drawPie(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 914 of file qpainterpath.cpp.

◆ arcTo() [2/2]

void QPainterPath::arcTo ( qreal x,
qreal y,
qreal w,
qreal h,
qreal startAngle,
qreal arcLength )
inline

Definition at line 249 of file qpainterpath.h.

◆ boundingRect()

QRectF QPainterPath::boundingRect ( ) const

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

See also
controlPointRect()

Definition at line 1456 of file qpainterpath.cpp.

◆ capacity()

int QPainterPath::capacity ( ) const

Returns the number of elements allocated by the QPainterPath.

See also
clear(), reserve()
Since
5.13

Definition at line 629 of file qpainterpath.cpp.

◆ clear()

void QPainterPath::clear ( )

Clears the path elements stored.

This allows the path to reuse previous memory allocations.

See also
reserve(), capacity()
Since
5.13

Definition at line 595 of file qpainterpath.cpp.

◆ closeSubpath()

void QPainterPath::closeSubpath ( )

Closes the current subpath by drawing a line to the beginning of the subpath, automatically starting a new path.

The current point of the new path is (0, 0).

If the subpath does not contain any elements, this function does nothing.

See also
moveTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 649 of file qpainterpath.cpp.

◆ connectPath()

void QPainterPath::connectPath ( const QPainterPath & path)

Connects the given path to this path by adding a line from the last element of this path to the first element of the given path.

See also
addPath(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 1261 of file qpainterpath.cpp.

◆ contains() [1/3]

bool QPainterPath::contains ( const QPainterPath & p) const
Since
4.3

Returns true if the given path p is contained within the current path. Returns false if any edges of the current path and p intersect.

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed.

See also
intersects()

Definition at line 3555 of file qpainterpath.cpp.

◆ contains() [2/3]

bool QPainterPath::contains ( const QPointF & point) const

Returns true if the given point is inside the path, otherwise returns false.

See also
intersects()

Definition at line 1803 of file qpainterpath.cpp.

◆ contains() [3/3]

bool QPainterPath::contains ( const QRectF & rect) const

Returns true if the given rectangle is inside the path, otherwise returns false.

Definition at line 2176 of file qpainterpath.cpp.

◆ controlPointRect()

QRectF QPainterPath::controlPointRect ( ) const

Returns the rectangle containing all the points and control points in this path.

This function is significantly faster to compute than the exact boundingRect(), and the returned rectangle is always a superset of the rectangle returned by boundingRect().

See also
boundingRect()

Definition at line 1477 of file qpainterpath.cpp.

◆ cubicTo() [1/2]

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

Adds a cubic Bezier curve between the current position and the given endPoint using the control points specified by c1, and c2.

After the curve is added, the current position is updated to be at the end point of the curve.

\table 100% \row

See also
quadTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 787 of file qpainterpath.cpp.

◆ cubicTo() [2/2]

void QPainterPath::cubicTo ( qreal ctrlPt1x,
qreal ctrlPt1y,
qreal ctrlPt2x,
qreal ctrlPt2y,
qreal endPtx,
qreal endPty )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds a cubic Bezier curve between the current position and the end point ({endPointX}, {endPointY}) with control points specified by ({c1X}, {c1Y}) and ({c2X}, {c2Y}).

Definition at line 259 of file qpainterpath.h.

◆ currentPosition()

QPointF QPainterPath::currentPosition ( ) const

Returns the current position of the path.

Definition at line 988 of file qpainterpath.cpp.

◆ elementAt()

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

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

See also
ElementType, elementCount(), isEmpty()

Definition at line 465 of file qpainterpath.cpp.

◆ elementCount()

int QPainterPath::elementCount ( ) const

Returns the number of path elements in the painter path.

See also
ElementType, elementAt(), isEmpty()

Definition at line 452 of file qpainterpath.cpp.

◆ fillRule()

Qt::FillRule QPainterPath::fillRule ( ) const

Returns the painter path's currently set fill rule.

See also
setFillRule()

Definition at line 1314 of file qpainterpath.cpp.

◆ intersected()

QPainterPath QPainterPath::intersected ( const QPainterPath & p) const
nodiscard
Since
4.3

Returns a path which is the intersection of this path's fill area and p's fill area. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

Definition at line 3479 of file qpainterpath.cpp.

◆ intersects() [1/2]

bool QPainterPath::intersects ( const QPainterPath & p) const
Since
4.3

Returns true if the current path intersects at any point the given path p. Also returns true if the current path contains or is contained by any part of p.

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed.

See also
contains()

Definition at line 3533 of file qpainterpath.cpp.

◆ intersects() [2/2]

bool QPainterPath::intersects ( const QRectF & rectangle) const

Returns true if any point in the given rectangle intersects the path; otherwise returns false.

There is an intersection if any of the lines making up the rectangle crosses a part of the path or if any part of the rectangle overlaps with any area enclosed by the path. This function respects the current fillRule to determine what is considered inside the path.

See also
contains()

Definition at line 2075 of file qpainterpath.cpp.

◆ isCachingEnabled()

bool QPainterPath::isCachingEnabled ( ) const

Returns true if caching is enabled; otherwise returns false.

Since
6.10
See also
setCachingEnabled()

Definition at line 2841 of file qpainterpath.cpp.

◆ isEmpty()

bool QPainterPath::isEmpty ( ) const

Returns true if either there are no elements in this path, or if the only element is a MoveToElement; otherwise returns false.

See also
elementCount()

Definition at line 1498 of file qpainterpath.cpp.

◆ length()

qreal QPainterPath::length ( ) const

Returns the length of the current path.

Definition at line 2882 of file qpainterpath.cpp.

◆ lineTo() [1/2]

void QPainterPath::lineTo ( const QPointF & endPoint)

Adds a straight line from the current position to the given endPoint.

After the line is drawn, the current position is updated to be at the end point of the line.

See also
addPolygon(), addRect(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 729 of file qpainterpath.cpp.

◆ lineTo() [2/2]

void QPainterPath::lineTo ( qreal x,
qreal y )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Draws a line from the current position to the point ({x}, {y}).

Definition at line 244 of file qpainterpath.h.

◆ moveTo() [1/2]

void QPainterPath::moveTo ( const QPointF & point)

Moves the current point to the given point, implicitly starting a new subpath and closing the previous one.

See also
closeSubpath(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 679 of file qpainterpath.cpp.

◆ moveTo() [2/2]

void QPainterPath::moveTo ( qreal x,
qreal y )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Moves the current position to ({x}, {y}) and starts a new subpath, implicitly closing the previous path.

Definition at line 239 of file qpainterpath.h.

◆ operator!=()

bool QPainterPath::operator!= ( const QPainterPath & path) const

Returns true if this painter path differs from the given path.

Note that comparing paths may involve a per element comparison which can be slow for complex paths.

See also
operator==()

Definition at line 2306 of file qpainterpath.cpp.

◆ operator&()

QPainterPath QPainterPath::operator& ( const QPainterPath & other) const
Since
4.5

Returns the intersection of this path and the other path.

See also
intersected(), operator&=(), united(), operator|()

Definition at line 2318 of file qpainterpath.cpp.

◆ operator&=()

QPainterPath & QPainterPath::operator&= ( const QPainterPath & other)
Since
4.5

Intersects this path with other and returns a reference to this path.

See also
intersected(), operator&(), operator|=()

Definition at line 2367 of file qpainterpath.cpp.

◆ operator+()

QPainterPath QPainterPath::operator+ ( const QPainterPath & other) const
Since
4.5

Returns the union of this path and the other path. This function is equivalent to operator|().

See also
united(), operator+=(), operator-()

Definition at line 2343 of file qpainterpath.cpp.

◆ operator+=()

QPainterPath & QPainterPath::operator+= ( const QPainterPath & other)
Since
4.5

Unites this path with other, and returns a reference to this path. This is equivalent to operator|=().

See also
united(), operator+(), operator-=()

Definition at line 2392 of file qpainterpath.cpp.

◆ operator-()

QPainterPath QPainterPath::operator- ( const QPainterPath & other) const
Since
4.5

Subtracts the other path from a copy of this path, and returns the copy.

See also
subtracted(), operator-=(), operator+()

Definition at line 2355 of file qpainterpath.cpp.

◆ operator-=()

QPainterPath & QPainterPath::operator-= ( const QPainterPath & other)
Since
4.5

Subtracts other from this path, and returns a reference to this path.

See also
subtracted(), operator-(), operator+=()

Definition at line 2405 of file qpainterpath.cpp.

◆ operator=()

QPainterPath & QPainterPath::operator= ( const QPainterPath & path)

Assigns the given path to this painter path.

Move-assigns other to this QPainterPath instance.

See also
QPainterPath()
Since
5.2

Definition at line 558 of file qpainterpath.cpp.

◆ operator==()

bool QPainterPath::operator== ( const QPainterPath & path) const

Returns true if this painterpath is equal to the given path.

Note that comparing paths may involve a per element comparison which can be slow for complex paths.

See also
operator!=()

Definition at line 2265 of file qpainterpath.cpp.

◆ operator|()

QPainterPath QPainterPath::operator| ( const QPainterPath & other) const
Since
4.5

Returns the union of this path and the other path.

See also
united(), operator|=(), intersected(), operator&()

Definition at line 2330 of file qpainterpath.cpp.

◆ operator|=()

QPainterPath & QPainterPath::operator|= ( const QPainterPath & other)
Since
4.5

Unites this path with other and returns a reference to this path.

See also
united(), operator|(), operator&=()

Definition at line 2379 of file qpainterpath.cpp.

◆ percentAtLength()

qreal QPainterPath::percentAtLength ( qreal len) const

Returns percentage of the whole path at the specified length len.

Note that similarly to other percent methods, the percentage measurement is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 2930 of file qpainterpath.cpp.

◆ pointAtPercent()

QPointF QPainterPath::pointAtPercent ( qreal t) const

Returns the point at at the percentage t of the current path.

The argument t has to be between 0 and 1.

Note that similarly to other percent methods, the percentage measurement is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 3103 of file qpainterpath.cpp.

◆ quadTo() [1/2]

void QPainterPath::quadTo ( const QPointF & c,
const QPointF & endPoint )

Adds a quadratic Bezier curve between the current position and the given endPoint with the control point specified by c.

After the curve is added, the current point is updated to be at the end point of the curve.

See also
cubicTo(), {QPainterPath#Composing a QPainterPath}{Composing a QPainterPath}

Definition at line 843 of file qpainterpath.cpp.

◆ quadTo() [2/2]

void QPainterPath::quadTo ( qreal ctrlPtx,
qreal ctrlPty,
qreal endPtx,
qreal endPty )
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.Adds a quadratic Bezier curve between the current point and the endpoint ({endPointX}, {endPointY}) with the control point specified by ({cx}, {cy}).

Definition at line 266 of file qpainterpath.h.

◆ reserve()

void QPainterPath::reserve ( int size)

Reserves a given amount of elements in QPainterPath's internal memory.

Attempts to allocate memory for at least size elements.

See also
clear(), capacity(), QList::reserve()
Since
5.13

Definition at line 613 of file qpainterpath.cpp.

◆ setCachingEnabled()

void QPainterPath::setCachingEnabled ( bool enabled)

Enables or disables length caching according to the value of enabled.

Enabling caching speeds up repeated calls to the member functions involving path length and percentage values, such as length(), percentAtLength(), pointAtPercent() etc., at the cost of some extra memory usage for storage of intermediate calculations. By default it is disabled.

Disabling caching will release any allocated cache memory.

Since
6.10
See also
isCachingEnabled(), length(), percentAtLength(), pointAtPercent(), trimmed()

Definition at line 2859 of file qpainterpath.cpp.

◆ setElementPositionAt()

void QPainterPath::setElementPositionAt ( int index,
qreal x,
qreal y )
Since
4.2

Sets the x and y coordinate of the element at index index to x and y.

Definition at line 480 of file qpainterpath.cpp.

◆ setFillRule()

void QPainterPath::setFillRule ( Qt::FillRule fillRule)

Sets the fill rule of the painter path to the given fillRule.

Qt provides two methods for filling paths:

\table \header

See also
fillRule()

Definition at line 1336 of file qpainterpath.cpp.

◆ simplified()

QPainterPath QPainterPath::simplified ( ) const
nodiscard
Since
4.4

Returns a simplified version of this path. This implies merging all subpaths that intersect, and returning a path containing no intersecting edges. Consecutive parallel lines will also be merged. The simplified path will always use the default fill rule, Qt::OddEvenFill. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

Definition at line 3514 of file qpainterpath.cpp.

◆ slopeAtPercent()

qreal QPainterPath::slopeAtPercent ( qreal t) const

Returns the slope of the path at the percentage t.

The argument t has to be between 0 and 1.

Note that similarly to other percent methods, the percentage measurement is not linear with regards to the length, if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations.

Definition at line 3166 of file qpainterpath.cpp.

◆ subtracted()

QPainterPath QPainterPath::subtracted ( const QPainterPath & p) const
nodiscard
Since
4.3

Returns a path which is p's fill area subtracted from this path's fill area.

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

Definition at line 3497 of file qpainterpath.cpp.

◆ swap()

void QPainterPath::swap ( QPainterPath & other)
inlinenoexcept
Since
4.8 \memberswap{painer path}

Definition at line 63 of file qpainterpath.h.

◆ toFillPolygon()

QPolygonF QPainterPath::toFillPolygon ( const QTransform & matrix = QTransform()) const

Converts the path into a polygon using the QTransform matrix, and returns the polygon.

The polygon is created by first converting all subpaths to polygons, then using a rewinding technique to make sure that overlapping subpaths can be filled using the correct fill rule.

Note that rewinding inserts addition lines in the polygon so the outline of the fill polygon does not match the outline of the path.

See also
toSubpathPolygons(), toFillPolygons(), {QPainterPath::QPainterPath Conversion}{QPainterPath Conversion}

Definition at line 2818 of file qpainterpath.cpp.

◆ toFillPolygons()

QList< QPolygonF > QPainterPath::toFillPolygons ( const QTransform & matrix = QTransform()) const

Converts the path into a list of polygons using the QTransform matrix, and returns the list.

The function differs from the toFillPolygon() function in that it creates several polygons. It is provided because it is usually faster to draw several small polygons than to draw one large polygon, even though the total number of points drawn is the same.

The toFillPolygons() function differs from the toSubpathPolygons() function in that it create only polygon for subpaths that have overlapping bounding rectangles.

Like the toFillPolygon() function, this function uses a rewinding technique to make sure that overlapping subpaths can be filled using the correct fill rule. Note that rewinding inserts addition lines in the polygons so the outline of the fill polygon does not match the outline of the path.

See also
toSubpathPolygons(), toFillPolygon(), {QPainterPath::QPainterPath Conversion}{QPainterPath Conversion}

Definition at line 1632 of file qpainterpath.cpp.

◆ toReversed()

QPainterPath QPainterPath::toReversed ( ) const
nodiscard

Creates and returns a reversed copy of the path.

It is the order of the elements that is reversed: If a QPainterPath is composed by calling the moveTo(), lineTo() and cubicTo() functions in the specified order, the reversed copy is composed by calling cubicTo(), lineTo() and moveTo().

Definition at line 1511 of file qpainterpath.cpp.

◆ toSubpathPolygons()

QList< QPolygonF > QPainterPath::toSubpathPolygons ( const QTransform & matrix = QTransform()) const

Converts the path into a list of polygons using the QTransform matrix, and returns the list.

This function creates one polygon for each subpath regardless of intersecting subpaths (i.e. overlapping bounding rectangles). To make sure that such overlapping subpaths are filled correctly, use the toFillPolygons() function instead.

See also
toFillPolygons(), toFillPolygon(), {QPainterPath::QPainterPath Conversion}{QPainterPath Conversion}

Definition at line 1565 of file qpainterpath.cpp.

◆ translate() [1/2]

void QPainterPath::translate ( const QPointF & offset)
inline

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Translates all elements in the path by the given offset.

See also
translated()

Definition at line 298 of file qpainterpath.h.

◆ translate() [2/2]

void QPainterPath::translate ( qreal dx,
qreal dy )

Translates all elements in the path by ({dx}, {dy}).

Since
4.6
See also
translated()

Definition at line 2118 of file qpainterpath.cpp.

◆ translated() [1/2]

QPainterPath QPainterPath::translated ( const QPointF & offset) const
inlinenodiscard

This is an overloaded member function, provided for convenience. It differs from the above function only in what argument(s) it accepts.

Since
4.6

Returns a copy of the path that is translated by the given offset.

See also
translate()

Definition at line 301 of file qpainterpath.h.

◆ translated() [2/2]

QPainterPath QPainterPath::translated ( qreal dx,
qreal dy ) const
nodiscard

Returns a copy of the path that is translated by ({dx}, {dy}).

Since
4.6
See also
translate()

Definition at line 2153 of file qpainterpath.cpp.

◆ trimmed()

QPainterPath QPainterPath::trimmed ( qreal fromFraction,
qreal toFraction,
qreal offset = 0 ) const
nodiscard
Since
6.10

Returns the section of the path between the length fractions fromFraction and toFraction. The effective range of the fractions are from 0, denoting the start point of the path, to 1, denoting its end point. The fractions are linear with respect to path length, in contrast to the percentage t values.

The value of offset will be added to the fraction values. If that causes an over- or underflow of the [0, 1] range, the values will be wrapped around, as will the resulting path. The effective range of the offset is between -1 and 1.

Repeated calls to this function can be optimized by {enabling caching}{setCachingEnabled()}.

See also
length(), percentAtLength(), setCachingEnabled()

Definition at line 3219 of file qpainterpath.cpp.

◆ united()

QPainterPath QPainterPath::united ( const QPainterPath & p) const
nodiscard
Since
4.3

Returns a path which is the union of this path's fill area and p's fill area.

Set operations on paths will treat the paths as areas. Non-closed paths will be treated as implicitly closed. Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections.

See also
intersected(), subtracted()

Definition at line 3464 of file qpainterpath.cpp.

◆ operator<<

Q_GUI_EXPORT QDataStream & operator<< ( QDataStream & stream,
const QPainterPath & path )
friend

Writes the given painter path to the given stream, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 2420 of file qpainterpath.cpp.

◆ operator>>

Q_GUI_EXPORT QDataStream & operator>> ( QDataStream & stream,
QPainterPath & path )
friend

Reads a painter path from the given stream into the specified path, and returns a reference to the stream.

See also
{Serializing Qt Data Types}

Definition at line 2447 of file qpainterpath.cpp.

◆ QPainterPathPrivate

friend class QPainterPathPrivate
friend

Definition at line 180 of file qpainterpath.h.

◆ QPainterPathStroker

friend class QPainterPathStroker
friend

Definition at line 178 of file qpainterpath.h.

◆ QPainterPathStrokerPrivate

friend class QPainterPathStrokerPrivate
friend

Definition at line 179 of file qpainterpath.h.

◆ QTransform

friend class QTransform
friend

Definition at line 181 of file qpainterpath.h.

◆ qtVectorPathForPath

Q_GUI_EXPORT const QVectorPath & qtVectorPathForPath ( const QPainterPath & path)
friend

Definition at line 95 of file qpaintengineex.cpp.

◆ QVectorPath

friend class QVectorPath
friend

Definition at line 182 of file qpainterpath.h.


The documentation for this class was generated from the following files: