On this page

QCPainterPath Class

QCPainterPath is the native path format of QCPainter. More...

Header: #include <QCPainterPath>

Public Functions

QCPainterPath()
void addPath(const QCPainterPath &path, const QTransform &transform = QTransform())
void arc(float centerX, float centerY, float radius, float a0, float a1, QCPainter::PathWinding direction = QCPainter::PathWinding::ClockWise, bool isConnected = true)
void arc(QPointF centerPoint, float radius, float a0, float a1, QCPainter::PathWinding direction = QCPainter::PathWinding::ClockWise, bool isConnected = true)
void arcTo(QPointF point1, QPointF point2, float radius)
void arcTo(float x1, float y1, float x2, float y2, float radius)
void bezierCurveTo(QPointF controlPoint1, QPointF controlPoint2, QPointF endPoint)
void bezierCurveTo(float cp1X, float cp1Y, float cp2X, float cp2Y, float x, float y)
void circle(float x, float y, float radius)
void circle(QPointF centerPoint, float radius)
void clear()
void closePath()
qsizetype commandsCapacity() const
qsizetype commandsDataCapacity() const
qsizetype commandsDataSize() const
qsizetype commandsSize() const
QPointF currentPosition() const
void ellipse(float x, float y, float radiusX, float radiusY)
void ellipse(const QRectF &rect)
bool isEmpty() const
void lineTo(QPointF point)
void lineTo(float x, float y)
void moveTo(QPointF point)
void moveTo(float x, float y)
void quadraticCurveTo(QPointF controlPoint, QPointF endPoint)
void quadraticCurveTo(float cpX, float cpY, float x, float y)
void rect(float x, float y, float width, float height)
void rect(const QRectF &rect)
void reserveCommands(qsizetype size)
void reserveCommandsData(qsizetype size)
void roundRect(float x, float y, float width, float height, float radius)
void roundRect(float x, float y, float width, float height, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)
void roundRect(const QRectF &rect, float radius)
void roundRect(const QRectF &rect, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)
void setPathWinding(QCPainter::PathWinding winding)
void squeeze()

Detailed Description

QCPainterPath provides a way to specify paths in the format that QCPainter uses internally. This gives better performance than using QPainterPath.

QCPainterPath has limited functionality compared to QPainterPath. In particular:

  • There are no methods for intersection or subtraction between two paths.
  • There is no method for translating the path.
  • There is no method for adding text.
  • The fillrule is always WindingFill (nonzero), OddEvenFill is not supported.

Member Function Documentation

QCPainterPath::QCPainterPath()

Constructs an empty path.

void QCPainterPath::addPath(const QCPainterPath &path, const QTransform &transform = QTransform())

Adds path into this path, transformed with transform matrix.

void QCPainterPath::arc(float centerX, float centerY, float radius, float a0, float a1, QCPainter::PathWinding direction = QCPainter::PathWinding::ClockWise, bool isConnected = true)

Creates an arc centered on QPointF(centerX, centerY) with the given radius, starting at an angle of a0 radians and ending at a1 radians. The arc spans the given direction. If isConnected is false, the previous path is closed and a new sub-path is started.

void QCPainterPath::arc(QPointF centerPoint, float radius, float a0, float a1, QCPainter::PathWinding direction = QCPainter::PathWinding::ClockWise, bool isConnected = true)

Creates an arc centered on centerPoint with the given radius, starting at an angle of a0 radians and ending at a1 radians. The arc spans the given direction. If isConnected is false, the previous path is closed and a new sub-path is started.

This is an overloaded function.

void QCPainterPath::arcTo(QPointF point1, QPointF point2, float radius)

Creates an arc using the points point1 and point2 with the given radius.

void QCPainterPath::arcTo(float x1, float y1, float x2, float y2, float radius)

Creates an arc using the points QPointF(x1, y1) and QPointF(x2, y2) with the given radius.

void QCPainterPath::bezierCurveTo(QPointF controlPoint1, QPointF controlPoint2, QPointF endPoint)

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

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

void QCPainterPath::bezierCurveTo(float cp1X, float cp1Y, float cp2X, float cp2Y, float x, float y)

void QCPainterPath::circle(float x, float y, float radius)

Adds a circle with center at QPointF(x, y) and the given radius to the path.

void QCPainterPath::circle(QPointF centerPoint, float radius)

Adds a circle with center at centerPoint and the given radius to the path.

This is an overloaded function.

void QCPainterPath::clear()

Clears the path commands and data.

Call this when the path commands change to recreate the path. This does not affect the memory usage, use reserveCommands(), reserveCommandsData() and squeeze() for that.

See also reserveCommands, reserveCommandsData, and squeeze.

void QCPainterPath::closePath()

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

qsizetype QCPainterPath::commandsCapacity() const

Returns the capacity of commands in the path.

See also reserveCommands.

qsizetype QCPainterPath::commandsDataCapacity() const

Returns the capacity of commands data in the path.

See also reserveCommandsData.

qsizetype QCPainterPath::commandsDataSize() const

Returns the amount of commands data in the path.

Commands data basically means the points required by the commands.

Note: Some path elements require several data points. For example closePath requires 0, moveTo and lineTo require 2, bezierCurveTo requires 6 and roundRect requires 34 data points.

qsizetype QCPainterPath::commandsSize() const

Returns the amount of commands in the path.

Note: Some path elements require several commands. For example moveTo and lineTo require 1 command, bezierCurveTo requires 6 commands and roundRect 10 commands.

QPointF QCPainterPath::currentPosition() const

Returns the current position of the path. This means position where previous path command (moveTo, lineTo, bezierCurveTo etc.) has ended. When the path is empty, returns (0.0, 0.0).

void QCPainterPath::ellipse(float x, float y, float radiusX, float radiusY)

Creates an ellipse centered at (x, y), with radii defined by radiusX, radiusY and adds it to the path as a closed subpath.

void QCPainterPath::ellipse(const QRectF &rect)

Creates an ellipse within the rectangle rect and adds it to the path as a closed subpath.

This is an overloaded function.

bool QCPainterPath::isEmpty() const

Returns true when the path is empty.

See also clear.

void QCPainterPath::lineTo(QPointF point)

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

void QCPainterPath::lineTo(float x, float y)

Draws a line from the current position to the point (x, y).

This is an overloaded function.

void QCPainterPath::moveTo(QPointF point)

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

void QCPainterPath::moveTo(float x, float y)

Moves the current position to (x, y) and starts a new subpath, implicitly closing the previous path.

This is an overloaded function.

void QCPainterPath::quadraticCurveTo(QPointF controlPoint, QPointF endPoint)

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

void QCPainterPath::quadraticCurveTo(float cpX, float cpY, float x, float y)

Adds a quadratic Bezier curve between the current point and the endpoint (x, y) with the control point specified by (cpX, cpY).

void QCPainterPath::rect(float x, float y, float width, float height)

Creates a rectangle positioned at QPointF(x, y) with the given width and height.

void QCPainterPath::rect(const QRectF &rect)

Creates a rectangle specified by rect

This is an overloaded function.

void QCPainterPath::reserveCommands(qsizetype size)

Reserves a given amount of commands in QCPainterPath's internal memory.

Attempts to allocate memory for at least size commands. Some path elements require multiple commands, see commandsSize.

See also squeeze.

void QCPainterPath::reserveCommandsData(qsizetype size)

Reserves a given amount of commands data in QCPainterPath's internal memory.

Attempts to allocate memory for at least size data points. Some path elements require multiple data points, see commandsDataSize.

See also squeeze.

void QCPainterPath::roundRect(float x, float y, float width, float height, float radius)

Adds the given rectangle x, y, width, height with rounded corners to the path. The corners are quarter circles with the given radius.

void QCPainterPath::roundRect(float x, float y, float width, float height, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)

Adds the rectangle x, y, width, height with rounded corners to the path. The corners are quarter circles with radius radiusTopLeft, radiusTopRight radiusBottomRight and radiusBottomLeft, respectively.

void QCPainterPath::roundRect(const QRectF &rect, float radius)

Adds the given rectangle rect with rounded corners to the path. The corners are quarter circles with the given radius.

This is an overloaded function.

void QCPainterPath::roundRect(const QRectF &rect, float radiusTopLeft, float radiusTopRight, float radiusBottomRight, float radiusBottomLeft)

Adds the rectangle rect with rounded corners to the path. The corners are quarter circles with radius radiusTopLeft, radiusTopRight radiusBottomRight and radiusBottomLeft, respectively.

This is an overloaded function.

void QCPainterPath::setPathWinding(QCPainter::PathWinding winding)

Sets the current sub-path winding to either QCPainter::CounterClockWise (default) or QCPainter::ClockWise. CounterClockWise draws solid subpaths while ClockWise draws holes.

void QCPainterPath::squeeze()

Releases any memory not required to store the path commands and data. This can be used to reduce the memory usage after calling the reserveCommands and reserveCommandsData method.

Normally this is not needed to be used, but it can be useful when the path size has been big due to reserving or adding many elements (lineTo, bezierCurveTo etc.) and then size is expected to be much smaller in future so calling first reserveCommands, reserveCommandsData and then squeeze, will release some memory.

See also reserveCommands and reserveCommandsData.

© 2025 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 the GNU 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.