QPainterPath Class
QPainterPath 类为绘画操作提供了一个容器,使图形形状得以构建和重复使用。更多
Header: | #include <QPainterPath> |
CMake.QPainterPath 类 | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
qmake: | QT += gui |
- 所有成员(包括继承成员)的列表
- QPainterPath 属于绘画类和隐式共享类。
公共类型
class | Element |
enum | ElementType { MoveToElement, LineToElement, CurveToElement, CurveToDataElement } |
公共函数
QPainterPath() | |
QPainterPath(const QPointF &startPoint) | |
QPainterPath(const QPainterPath &path) | |
~QPainterPath() | |
void | addEllipse(const QRectF &boundingRectangle) |
void | addEllipse(const QPointF ¢er, qreal rx, qreal ry) |
void | addEllipse(qreal x, qreal y, qreal width, qreal height) |
void | addPath(const QPainterPath &path) |
void | addPolygon(const QPolygonF &polygon) |
void | addRect(const QRectF &rectangle) |
void | addRect(qreal x, qreal y, qreal width, qreal height) |
void | addRegion(const QRegion ®ion) |
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 | addText(const QPointF &point, const QFont &font, const QString &text) |
void | addText(qreal x, qreal y, const QFont &font, const QString &text) |
qreal | angleAtPercent(qreal t) const |
void | arcMoveTo(const QRectF &rectangle, qreal angle) |
void | arcMoveTo(qreal x, qreal y, qreal width, qreal height, qreal angle) |
void | arcTo(const QRectF &rectangle, qreal startAngle, qreal sweepLength) |
void | arcTo(qreal x, qreal y, qreal width, qreal height, qreal startAngle, qreal sweepLength) |
QRectF | boundingRect() const |
int | capacity() const |
void | clear() |
void | closeSubpath() |
void | connectPath(const QPainterPath &path) |
bool | contains(const QPainterPath &p) const |
bool | contains(const QPointF &point) const |
bool | contains(const QRectF &rectangle) const |
QRectF | controlPointRect() const |
void | cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &endPoint) |
void | cubicTo(qreal c1X, qreal c1Y, qreal c2X, qreal c2Y, qreal endPointX, qreal endPointY) |
QPointF | currentPosition() const |
QPainterPath::Element | elementAt(int index) const |
int | elementCount() const |
Qt::FillRule | fillRule() const |
QPainterPath | intersected(const QPainterPath &p) const |
bool | intersects(const QPainterPath &p) const |
bool | intersects(const QRectF &rectangle) const |
bool | isEmpty() const |
qreal | length() const |
void | lineTo(const QPointF &endPoint) |
void | lineTo(qreal x, qreal y) |
void | moveTo(const QPointF &point) |
void | moveTo(qreal x, qreal y) |
qreal | percentAtLength(qreal len) const |
QPointF | pointAtPercent(qreal t) const |
void | quadTo(const QPointF &c, const QPointF &endPoint) |
void | quadTo(qreal cx, qreal cy, qreal endPointX, qreal endPointY) |
void | reserve(int size) |
void | setElementPositionAt(int index, qreal x, qreal y) |
void | setFillRule(Qt::FillRule fillRule) |
QPainterPath | simplified() const |
qreal | slopeAtPercent(qreal t) const |
QPainterPath | subtracted(const QPainterPath &p) const |
void | swap(QPainterPath &other) |
QPolygonF | toFillPolygon(const QTransform &matrix = QTransform()) const |
QList<QPolygonF> | toFillPolygons(const QTransform &matrix = QTransform()) const |
QPainterPath | toReversed() const |
QList<QPolygonF> | toSubpathPolygons(const QTransform &matrix = QTransform()) const |
void | translate(qreal dx, qreal dy) |
void | translate(const QPointF &offset) |
QPainterPath | translated(qreal dx, qreal dy) const |
QPainterPath | translated(const QPointF &offset) const |
QPainterPath | united(const QPainterPath &p) const |
bool | operator!=(const QPainterPath &path) const |
QPainterPath | operator&(const QPainterPath &other) const |
QPainterPath & | operator&=(const QPainterPath &other) |
QPainterPath | operator+(const QPainterPath &other) const |
QPainterPath & | operator+=(const QPainterPath &other) |
QPainterPath | operator-(const QPainterPath &other) const |
QPainterPath & | operator-=(const QPainterPath &other) |
QPainterPath & | operator=(QPainterPath &&other) |
QPainterPath & | operator=(const QPainterPath &path) |
bool | operator==(const QPainterPath &path) const |
QPainterPath | operator|(const QPainterPath &other) const |
QPainterPath & | operator|=(const QPainterPath &other) |
相关非成员
QDataStream & | operator<<(QDataStream &stream, const QPainterPath &path) |
QDataStream & | operator>>(QDataStream &stream, QPainterPath &path) |
详细描述
绘画路径是一个由多个图形构件(如矩形、椭圆、直线和曲线)组成的对象。图形构件可以连接成封闭的子路径,例如矩形或椭圆。封闭路径的起点和终点是重合的。它们也可以作为非封闭子路径(如直线和曲线)独立存在。
QPainterPath 对象可用于填充、勾勒和剪切。要为给定的画家路径生成可填充的轮廓,可使用QPainterPathStroker 类。与普通绘图操作相比,绘制路径的主要优点是只需创建一次复杂形状,然后只需调用QPainter::drawPath() 函数就能多次绘制。
QPainterPath 提供了一系列函数,可用于获取路径及其元素的相关信息。此外,还可以使用toReversed() 函数反转元素的顺序。此外,还有几个函数可将此画家路径对象转换为多边形表示法。
组成 QPainterPath
QPainterPath 对象可作为空路径、给定起点或另一个 QPainterPath 对象的副本来构建。创建后,可使用lineTo(),arcTo(),cubicTo() 和quadTo() 函数将线条和曲线添加到路径中。线条和曲线从currentPosition() 延伸到作为参数传递的位置。
QPainterPath 对象的currentPosition() 始终是最后添加的子路径的结束位置(或初始起点)。使用moveTo() 函数移动currentPosition() 而不添加组件。moveTo() 函数隐式启动了一个新的子路径,并关闭了上一个子路径。另一种启动新子路径的方法是调用closeSubpath() 函数,该函数通过从currentPosition() 添加一行回到路径的起始位置来关闭当前路径。请注意,新路径的初始currentPosition() 将为(0, 0)。
QPainterPath 类还提供了几个方便的函数,用于向画家路径添加封闭的子路径:addEllipse(),addPath(),addRect(),addRegion() 和addText() 。addPolygon() 函数用于添加非封闭子路径。事实上,这些函数都是moveTo(),lineTo() 和cubicTo() 操作的集合。
此外,还可以使用connectPath() 函数在当前路径上添加一个路径。但要注意的是,该函数会通过添加一行将当前路径的最后一个元素连接到给定路径的第一个元素。
下面的代码片段展示了如何使用 QPainterPath 对象:
![]() | QPainterPath path; path.addRect(20, 20, 60, 60); path.moveTo(0, 0); path.cubicTo(99, 0, 50, 50, 99, 99); path.cubicTo(0, 99, 50, 50, 0, 0); QPainter painter(this); painter.fillRect(0, 0, 100, 100, Qt::white); painter.setPen(QPen(QColor(79, 106, 25), 1, Qt::SolidLine, Qt::FlatCap, Qt::MiterJoin)); painter.setBrush(QColor(122, 163, 39)); painter.drawPath(path); |
绘制路径在构建之初是空的。我们首先添加一个矩形,它是一个封闭的子路径。然后,我们添加两条贝塞尔曲线,它们共同构成一个封闭的子路径,尽管它们各自并不封闭。最后绘制整个路径。路径的填充使用默认的填充规则Qt::OddEvenFill 。Qt 提供了两种填充路径的方法:
有关规则的定义,请参阅Qt::FillRule 文档。可以使用fillRule() 函数检索画家路径当前设置的填充规则,也可以使用setFillRule() 函数更改填充规则。
QPainterPath 信息
QPainterPath 类提供了一系列函数,用于返回路径及其元素的信息。
currentPosition() 函数返回最后添加的子路径的终点(或初始起点)。elementAt() 函数可用于检索各种子路径元素,使用elementCount() 函数可检索元素的数量,而isEmpty() 函数可告知此 QPainterPath 对象是否包含任何元素。
controlPointRect() 函数返回包含该路径中所有点和控制点的矩形。该函数的计算速度明显快于精确的boundingRect() 函数,后者以浮点精度返回该画家路径的边界矩形。
最后,QPainterPath 提供了contains() 函数和intersects() 函数,前者可用于确定给定的点或矩形是否在路径内部,后者可确定给定矩形内部的任何点是否也在路径内部。
QPainterPath 转换
出于兼容性原因,可能需要简化画家路径的表示:QPainterPath 提供了toFillPolygon(),toFillPolygons() 和toSubpathPolygons() 函数,用于将画家路径转换为多边形。toFillPolygon() 函数将绘制路径返回为单个多边形,而后两个函数则返回多边形列表。
之所以提供toFillPolygons() 和toSubpathPolygons() 函数,是因为绘制多个小多边形通常比绘制一个大多边形要快,即使绘制的点总数相同。这两个函数的区别在于它们返回的多边形数量:toSubpathPolygons() 为每个子路径创建一个多边形,而不考虑相交的子路径(即重叠的边界矩形),而toFillPolygons() 函数只为重叠的子路径创建一个多边形。
toFillPolygon() 和toFillPolygons() 函数首先将所有子路径转换为多边形,然后使用回卷技术确保重叠的子路径可以使用正确的填充规则进行填充。请注意,倒带会在多边形中插入额外的线条,因此填充多边形的轮廓与路径的轮廓不一致。
示例
Qt 提供了绘制路径示例和矢量变形示例,它们位于 Qt 的示例目录中。
绘制路径示例展示了如何使用绘制路径来构建复杂的渲染形状,并让用户尝试填充和描边。矢量变形示例展示了如何使用 QPainterPath 绘制文本。
另请参阅 QPainterPathStroker,QPainter,QRegion 和绘制路径示例。
成员类型文档
enum QPainterPath::ElementType
此枚举描述了用于连接子路径中顶点的元素类型。
请注意,使用addEllipse(),addPath(),addPolygon(),addRect(),addRegion() 和addText() 方便函数添加为封闭子路径的元素,实际上是使用moveTo(),lineTo() 和cubicTo() 函数添加为路径的独立元素集合。
常量 | 值 | 说明 |
---|---|---|
QPainterPath::MoveToElement | 0 | 新的子路径。另请参阅moveTo()。 |
QPainterPath::LineToElement | 1 | 一行。另请参见lineTo()。 |
QPainterPath::CurveToElement | 2 | 一条曲线。另请参阅cubicTo() 和quadTo()。 |
QPainterPath::CurveToDataElement | 3 | 在 CurveToElement 元素中描述曲线所需的额外数据。 |
另请参阅 elementAt() 和elementCount()。
成员函数文档
[noexcept]
QPainterPath::QPainterPath()
构造一个空的 QPainterPath 对象。
[explicit]
QPainterPath::QPainterPath(const QPointF &startPoint)
创建 QPainterPath 对象,并将给定的startPoint 作为其当前位置。
QPainterPath::QPainterPath(const QPainterPath &path)
创建一个 QPainterPath 对象,它是给定path 的副本。
另请参阅 operator=().
[noexcept]
QPainterPath::~QPainterPath()
销毁QPainterPath 对象。
void QPainterPath::addEllipse(const QRectF &boundingRectangle)
在指定的boundingRectangle 范围内创建一个椭圆,并将其作为封闭子路径添加到绘制路径中。
椭圆由一条顺时针方向的曲线组成,起点和终点均为零度(3 点钟位置)。
![]() | QLinearGradient myGradient; QPen myPen; QRectF boundingRectangle; QPainterPath myPath; myPath.addEllipse(boundingRectangle); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); |
另请参阅 arcTo()、QPainter::drawEllipse() 和Composing a QPainterPath 。
void QPainterPath::addEllipse(const QPointF ¢er, qreal rx, qreal ry)
这是一个重载函数。
创建一个位于center 、半径分别为rx 和ry 的椭圆,并将其作为封闭子路径添加到绘制路径中。
void QPainterPath::addEllipse(qreal x, qreal y, qreal width, qreal height)
这是一个重载函数。
在其左上角 (x,y),width 和height 处定义的矩形边界内创建一个椭圆,并将其作为封闭子路径添加到绘制路径中。
void QPainterPath::addPath(const QPainterPath &path)
将给定的path 作为封闭子路径添加到此路径中。
另请参阅 connectPath() 和Composing a QPainterPath 。
void QPainterPath::addPolygon(const QPolygonF &polygon)
将给定的polygon 作为(未封闭)子路径添加到路径中。
请注意,添加多边形后的当前位置是polygon 中的最后一点。要画线回到第一点,请使用closeSubpath() 函数。
![]() | QLinearGradient myGradient; QPen myPen; QPolygonF myPolygon; QPainterPath myPath; myPath.addPolygon(myPolygon); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); |
另请参见 lineTo() 和Composing a QPainterPath 。
void QPainterPath::addRect(const QRectF &rectangle)
将给定的rectangle 作为封闭子路径添加到此路径中。
rectangle 会以顺时针方向的线组形式添加。添加rectangle 后,画家路径的当前位置是矩形的左上角。
![]() | QLinearGradient myGradient; QPen myPen; QRectF myRectangle; QPainterPath myPath; myPath.addRect(myRectangle); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); |
另请参阅 addRegion()、lineTo() 和Composing a QPainterPath 。
void QPainterPath::addRect(qreal x, qreal y, qreal width, qreal height)
这是一个重载函数。
在位置 (x,y) 处添加一个矩形,并将给定的width 和height 作为封闭子路径。
void QPainterPath::addRegion(const QRegion ®ion)
将给定的region 添加到路径中,将区域中的每个矩形添加为单独的封闭子路径。
另请参阅 addRect() 和Composing a QPainterPath 。
void QPainterPath::addRoundedRect(const QRectF &rect, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize)
将给定的圆角矩形rect 添加到路径中。
xRadius 和yRadius 参数指定了定义圆角矩形四角的椭圆的半径。当mode 为Qt::RelativeSize 时,xRadius 和yRadius 分别以矩形宽度和高度一半的百分比指定,范围应在 0.0 到 100.0 之间。
另请参见 addRect()。
void QPainterPath::addRoundedRect(qreal x, qreal y, qreal w, qreal h, qreal xRadius, qreal yRadius, Qt::SizeMode mode = Qt::AbsoluteSize)
这是一个重载函数。
将给定的圆角矩形x,y,w,h 添加到路径中。
void QPainterPath::addText(const QPointF &point, const QFont &font, const QString &text)
将给定的text 添加到此路径,作为从所提供的font 创建的一组封闭子路径。子路径的位置会使文本基线的左端位于指定的point 。
某些字体可能会产生重叠的子路径,需要使用Qt::WindingFill
填充规则才能正确渲染。
![]() | QLinearGradient myGradient; QPen myPen; QFont myFont; QPointF baseline(x, y); QPainterPath myPath; myPath.addText(baseline, myFont, tr("Qt")); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); |
另请参阅 QPainter::drawText(),Composing a QPainterPath, 和setFillRule().
void QPainterPath::addText(qreal x, qreal y, const QFont &font, const QString &text)
这是一个重载函数。
将给定的text 添加到此路径,作为从所提供的font 创建的一组封闭子路径。子路径的位置将使文本基线的左端位于 (x,y) 指定的点上。
qreal QPainterPath::angleAtPercent(qreal t) const
返回百分比t 处的路径切线角度。参数t 必须介于 0 和 1 之间。
角度的正值表示逆时针方向,负值表示顺时针方向。零度位于 3 点钟位置。
需要注意的是,与其他百分比方法类似,如果路径中存在曲线,百分比测量与长度的关系也不是线性的。如果存在曲线,百分比参数将映射到贝塞尔方程的 t 参数。
void QPainterPath::arcMoveTo(const QRectF &rectangle, qreal angle)
创建一个移动到的弧线,该弧线在angle 处占据给定的rectangle 。
角度以度为单位。可以使用负角度指定顺时针方向的弧线。
void QPainterPath::arcMoveTo(qreal x, qreal y, qreal width, qreal height, qreal angle)
这是一个重载函数。
在QRectF(x,y,width,height) 的弧上创建一个移动到angle 。
void QPainterPath::arcTo(const QRectF &rectangle, qreal startAngle, qreal sweepLength)
创建一条占用给定rectangle 的弧线,从指定的startAngle 开始,逆时针方向延伸sweepLength 度。
角度以度为单位。可以使用负角度指定顺时针方向的弧线。
请注意,如果弧的起点和当前位置尚未连接,则此函数会将它们连接起来。添加弧线后,当前位置就是弧线的最后一点。要画线回到第一点,请使用closeSubpath() 函数。
![]() | QPainterPath myPath; myPath.moveTo(center); myPath.arcTo(boundingRect, startAngle, sweepLength); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); |
另请参见 arcMoveTo()、addEllipse()、QPainter::drawArc()、QPainter::drawPie() 和Composing a QPainterPath 。
void QPainterPath::arcTo(qreal x, qreal y, qreal width, qreal height, qreal startAngle, qreal sweepLength)
这是一个重载函数。
创建一条占据矩形QRectF(x,y,width,height) 的弧线,从指定的startAngle 开始,逆时针方向延伸sweepLength 度。
QRectF QPainterPath::boundingRect() const
以浮点精度的矩形返回此绘制路径的边界矩形。
另请参阅 controlPointRect()。
int QPainterPath::capacity() const
返回QPainterPath 分配的元素个数。
void QPainterPath::clear()
清除存储的路径元素。
这样,路径就可以重复使用以前的内存分配。
void QPainterPath::closeSubpath()
在子路径的起点画一条直线,关闭当前子路径,自动开始一条新路径。新路径的当前点是(0,0)。
如果子路径不包含任何元素,此函数不会执行任何操作。
另请参见 moveTo() 和Composing a QPainterPath 。
void QPainterPath::connectPath(const QPainterPath &path)
将给定的path 连接到此路径,方法是从此路径的最后一个元素到给定路径的第一个元素之间添加一行。
另请参阅 addPath() 和Composing a QPainterPath 。
bool QPainterPath::contains(const QPainterPath &p) const
如果给定路径p 包含在当前路径中,则返回true
。如果当前路径的任何边与p 相交,则返回false
。
路径上的设置操作将把路径视为区域。非封闭路径将被视为隐式封闭路径。
另请参阅 intersects()。
bool QPainterPath::contains(const QPointF &point) const
如果给定的point 位于路径内,则返回true
,否则返回false
。
另请参阅 intersects() 。
bool QPainterPath::contains(const QRectF &rectangle) const
如果给定的rectangle 在路径内,则返回true
,否则返回false
。
QRectF QPainterPath::controlPointRect() const
返回包含此路径中所有点和控制点的矩形。
此函数的计算速度明显快于精确的boundingRect(),而且返回的矩形总是boundingRect() 所返回矩形的超集。
另请参见 boundingRect()。
void QPainterPath::cubicTo(const QPointF &c1, const QPointF &c2, const QPointF &endPoint)
使用c1, 和c2 指定的控制点,在当前位置和给定的endPoint 之间添加一条立方贝塞尔曲线。
曲线添加完成后,当前位置将更新为曲线的终点。
![]() | QLinearGradient myGradient; QPen myPen; QPainterPath myPath; myPath.cubicTo(c1, c2, endPoint); QPainter painter(this); painter.setBrush(myGradient); painter.setPen(myPen); painter.drawPath(myPath); |
另请参阅 quadTo() 和Composing a QPainterPath 。
void QPainterPath::cubicTo(qreal c1X, qreal c1Y, qreal c2X, qreal c2Y, qreal endPointX, qreal endPointY)
这是一个重载函数。
在当前位置和终点 (endPointX,endPointY) 之间添加一条立方贝塞尔曲线,控制点由 (c1X,c1Y) 和 (c2X,c2Y) 指定。
QPointF QPainterPath::currentPosition() const
返回路径的当前位置。
QPainterPath::Element QPainterPath::elementAt(int index) const
返回画家路径中给定index 处的元素。
另请参见 ElementType,elementCount() 和isEmpty()。
int QPainterPath::elementCount() const
返回画家路径中路径元素的数量。
另请参阅 ElementType,elementAt() 和isEmpty()。
Qt::FillRule QPainterPath::fillRule() const
返回画家路径当前设置的填充规则。
另请参阅 setFillRule()。
QPainterPath QPainterPath::intersected(const QPainterPath &p) const
返回一条路径,该路径的填充区域与p 的填充区域相交。由于贝塞尔曲线相交处的数值不稳定,贝塞尔曲线可能会被平铺为线段。
bool QPainterPath::intersects(const QPainterPath &p) const
如果当前路径与给定路径p 相交,则返回true
。如果当前路径包含或被p 的任何部分包含,也会返回true
。
路径上的集合操作将把路径视为区域。非封闭路径将被视为隐式封闭路径。
另请参见 contains()。
bool QPainterPath::intersects(const QRectF &rectangle) const
如果给定的rectangle 中的任何一点与路径相交,则返回true
;否则返回false
。
如果组成矩形的任何一条线与路径的一部分交叉,或者矩形的任何一部分与路径所包围的任何区域重叠,则存在交点。此函数尊重当前的fillRule ,以确定路径内部的内容。
另请参见 contains()。
bool QPainterPath::isEmpty() const
如果该路径中没有元素,或者唯一的元素是MoveToElement ,则返回true
;否则返回false
。
另请参阅 elementCount() 。
qreal QPainterPath::length() const
返回当前路径的长度。
void QPainterPath::lineTo(const QPointF &endPoint)
从当前位置向给定的endPoint 添加一条直线。直线绘制完成后,当前位置将更新为直线的终点。
另请参阅 addPolygon(),addRect() 和Composing a QPainterPath 。
void QPainterPath::lineTo(qreal x, qreal y)
这是一个重载函数。
从当前位置到点 (x,y) 画一条直线。
void QPainterPath::moveTo(const QPointF &point)
将当前点移动到给定的point ,隐式启动一个新的子路径并关闭上一个子路径。
另请参阅 closeSubpath() 和Composing a QPainterPath 。
void QPainterPath::moveTo(qreal x, qreal y)
这是一个重载函数。
将当前位置移动到 (x,y) 并启动一个新的子路径,同时隐式关闭前一个路径。
qreal QPainterPath::percentAtLength(qreal len) const
返回指定长度处整个路径的百分比len 。
需要注意的是,与其他百分比方法类似,如果路径中存在曲线,百分比测量与长度的关系不是线性的。如果存在曲线,百分比参数将映射到贝塞尔方程的 t 参数。
QPointF QPainterPath::pointAtPercent(qreal t) const
返回当前路径t 百分比处的点。参数t 必须介于 0 和 1 之间。
需要注意的是,与其他百分比方法类似,如果路径中存在曲线,百分比测量与长度的关系不是线性的。如果存在曲线,百分比参数将被映射为贝塞尔方程的 t 参数。
void QPainterPath::quadTo(const QPointF &c, const QPointF &endPoint)
在当前位置和给定的endPoint 之间添加一条二次贝塞尔曲线,控制点由c 指定。
添加曲线后,当前点将更新为曲线的终点。
另请参阅 cubicTo() 和Composing a QPainterPath 。
void QPainterPath::quadTo(qreal cx, qreal cy, qreal endPointX, qreal endPointY)
这是一个重载函数。
在当前点和端点 (endPointX,endPointY) 之间添加一条二次贝塞尔曲线,控制点由 (cx,cy) 指定。
void QPainterPath::reserve(int size)
在QPainterPath 的内部内存中保留一定数量的元素。
尝试为至少size 个元素分配内存。
另请参阅 clear()、capacity() 和QList::reserve()。
void QPainterPath::setElementPositionAt(int index, qreal x, qreal y)
将索引index 处元素的 x 坐标和 y 坐标设置为x 和y 。
void QPainterPath::setFillRule(Qt::FillRule fillRule)
将绘制路径的填充规则设置为给定的fillRule 。Qt 提供了两种填充路径的方法:
另请参阅 fillRule().
QPainterPath QPainterPath::simplified() const
返回此路径的简化版本。这意味着要合并所有相交的子路径,并返回一条不包含相交边缘的路径。连续的平行线也会被合并。简化后的路径将始终使用默认的填充规则Qt::OddEvenFill 。由于贝塞尔曲线相交处的数值不稳定,贝塞尔曲线可能会被扁平化为线段。
qreal QPainterPath::slopeAtPercent(qreal t) const
返回路径在百分比t 上的斜率。参数t 必须介于 0 和 1 之间。
需要注意的是,与其他百分比方法类似,如果路径中存在曲线,百分比测量与长度的关系不是线性的。如果存在曲线,百分比参数将被映射为贝塞尔方程的 t 参数。
QPainterPath QPainterPath::subtracted(const QPainterPath &p) const
返回p 的填充区域减去此路径的填充区域的路径。
路径上的设置操作将把路径视为区域。非封闭路径将被视为隐式封闭路径。由于贝塞尔曲线相交处的数值不稳定,贝塞尔曲线可能会被扁平化为线段。
[noexcept]
void QPainterPath::swap(QPainterPath &other)
用other 替换该绘图路径。这一操作非常快速,从未出现过故障。
QPolygonF QPainterPath::toFillPolygon(const QTransform &matrix = QTransform()) const
使用QTransform matrix 将路径转换为多边形,并返回多边形。
创建多边形时,首先要将所有子路径转换为多边形,然后使用倒带技术确保可以使用正确的填充规则填充重叠的子路径。
请注意,倒带会在多边形中插入附加线,因此填充多边形的轮廓与路径的轮廓不一致。
另请参阅 toSubpathPolygons()、toFillPolygons() 和QPainterPath Conversion 。
QList<QPolygonF> QPainterPath::toFillPolygons(const QTransform &matrix = QTransform()) const
使用QTransform matrix 将路径转换为多边形列表,并返回列表。
该函数与toFillPolygon() 函数的不同之处在于,它会创建多个多边形。之所以提供该函数,是因为绘制多个小多边形通常比绘制一个大多边形要快,即使绘制的点总数相同。
toFillPolygons() 函数与toSubpathPolygons() 函数的不同之处在于,它只为具有重叠边界矩形的子路径创建多边形。
与toFillPolygon() 函数一样,该函数使用了倒带技术,以确保使用正确的填充规则填充重叠的子路径。请注意,倒带会在多边形中插入附加线,因此填充多边形的轮廓与路径的轮廓不一致。
另请参阅 toSubpathPolygons()、toFillPolygon() 和QPainterPath Conversion 。
QPainterPath QPainterPath::toReversed() const
创建并返回路径的反转副本。
反转的是元素的顺序:如果QPainterPath 是按指定顺序调用moveTo(),lineTo() 和cubicTo() 函数组成的,那么反转副本则是按cubicTo(),lineTo() 和moveTo() 函数组成的。
QList<QPolygonF> QPainterPath::toSubpathPolygons(const QTransform &matrix = QTransform()) const
使用QTransform matrix 将路径转换为多边形列表,并返回列表。
此函数为每个子路径创建一个多边形,而不考虑相交的子路径(即重叠的边界矩形)。为确保正确填充重叠的子路径,请使用toFillPolygons() 函数。
另请参见 toFillPolygons()、toFillPolygon() 和QPainterPath Conversion 。
void QPainterPath::translate(qreal dx, qreal dy)
用 (dx,dy) 翻译路径中的所有元素。
另请参见 translated().
void QPainterPath::translate(const QPointF &offset)
这是一个重载函数。
用给定的offset 转换路径中的所有元素。
另请参阅 translated() 。
QPainterPath QPainterPath::translated(qreal dx, qreal dy) const
返回由 (dx,dy) 翻译的路径的副本。
另请参见 translate().
QPainterPath QPainterPath::translated(const QPointF &offset) const
这是一个重载函数。
返回由给定offset 翻译的路径副本。
另请参阅 translate() 。
QPainterPath QPainterPath::united(const QPainterPath &p) const
返回一条路径,它是此路径的填充区域和p 的填充区域的结合。
路径上的设置操作将把路径视为区域。非封闭路径将被视为隐式封闭路径。由于贝塞尔曲线相交处的数值不稳定,贝塞尔曲线可能会被扁平化为线段。
另请参见 intersected() 和subtracted()。
bool QPainterPath::operator!=(const QPainterPath &path) const
如果该画家路径与给定的path 不同,则返回true
。
请注意,路径比较可能涉及每个元素的比较,对于复杂路径来说可能会比较慢。
另请参阅 operator==() 。
QPainterPath QPainterPath::operator&(const QPainterPath &other) const
返回此路径与other 路径的交集。
另请参阅 intersected()、operator&=()、united() 和operator|()。
QPainterPath &QPainterPath::operator&=(const QPainterPath &other)
将此路径与other 相交,并返回此路径的引用。
另请参阅 intersected()、operator&() 和operator|=()。
QPainterPath QPainterPath::operator+(const QPainterPath &other) const
返回此路径和other 路径的联合。此函数等同于 operator|()。
另请参阅 united()、operator+=() 和operator-()。
QPainterPath &QPainterPath::operator+=(const QPainterPath &other)
将此路径与other 结合,并返回此路径的引用。这等同于 operator|=()。
另请参阅 united()、operator+() 和operator-=()。
QPainterPath QPainterPath::operator-(const QPainterPath &other) const
从该路径的副本中减去other 路径,并返回副本。
另请参阅 subtracted()、operator-=() 和operator+()。
QPainterPath &QPainterPath::operator-=(const QPainterPath &other)
从该路径减去other ,并返回对该路径的引用。
另请参阅 subtracted()、operator-() 和operator+=()。
[noexcept]
QPainterPath &QPainterPath::operator=(QPainterPath &&other)
Move-assignsother 到此QPainterPath 实例。
QPainterPath &QPainterPath::operator=(const QPainterPath &path)
将给定的path 指定给此画家路径。
另请参阅 QPainterPath().
bool QPainterPath::operator==(const QPainterPath &path) const
如果此 painterpath 等于给定的path ,则返回true
。
请注意,路径比较可能涉及每个元素的比较,对于复杂路径来说可能会比较慢。
另请参阅 operator!=() 。
QPainterPath QPainterPath::operator|(const QPainterPath &other) const
返回此路径与other 路径的联合。
另请参阅 united()、operator|=()、intersected() 和operator&()。
QPainterPath &QPainterPath::operator|=(const QPainterPath &other)
将此路径与other 相结合,并返回此路径的引用。
另请参阅 united()、operator|() 和operator&=()。
相关非会员
QDataStream &operator<<(QDataStream &stream, const QPainterPath &path)
将给定的画家path 写入给定的stream ,并返回对stream 的引用。
另请参阅 序列化 Qt 数据类型。
QDataStream &operator>>(QDataStream &stream, QPainterPath &path)
从给定的stream 中读取画家路径到指定的path 中,并返回对stream 的引用。
另请参阅 序列化 Qt 数据类型。
© 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.