QPainterPath 类

The QPainterPath 类为描绘操作提供容器,使能够构造和重用图形形状。 更多...

头: #include <QPainterPath>
qmake: QT += gui

公共类型

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 (qreal x , qreal y , qreal width , qreal height )
void addEllipse (const QPointF & center , qreal rx , qreal ry )
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 & region )
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 = ...)
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
void closeSubpath ()
void connectPath (const QPainterPath & path )
bool contains (const QPointF & point ) const
bool contains (const QRectF & rectangle ) const
bool contains (const QPainterPath & p ) 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 QRectF & rectangle ) const
bool intersects (const QPainterPath & p ) 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 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 ) const
QPolygonF toFillPolygon (const QMatrix & matrix = QMatrix()) const
QList<QPolygonF> toFillPolygons (const QTransform & matrix ) const
QList<QPolygonF> toFillPolygons (const QMatrix & matrix = QMatrix()) const
QPainterPath toReversed () const
QList<QPolygonF> toSubpathPolygons (const QTransform & matrix ) const
QList<QPolygonF> toSubpathPolygons (const QMatrix & matrix = QMatrix()) 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= (const QPainterPath & path )
QPainterPath & operator= (QPainterPath && other )
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 )

详细描述

The QPainterPath 类为描绘操作提供容器,使能够构造和重用图形形状。

描绘器路径是由很多图形构建块 (譬如:矩形、椭圆、直线及曲线) 组成的对象。可以将构建块 (譬如:矩形或椭圆形) 拼接到封闭子路径中。封闭路径拥有的起点和终点重合。或者,它们可以作为未闭合的子路径 (譬如:直线和曲线) 独立存在。

A QPainterPath 对象可以用于填充、轮廓描绘及裁剪。要为给定描绘器路径生成可填充轮廓,使用 QPainterPathStroker 类。与正常绘制操作相比,描绘器路径的主要优点是只需创建复杂形状一次;那么可以多次绘制它们,仅使用调用 QPainter::drawPath () 函数。

QPainterPath 提供了可以用于获取路径及其元素有关信息的一批函数。此外,它是可能的反转元素次序使用 toReversed () 函数。还有几个函数能将此描绘器路径对象,转换成多边形表示。

合成 QPainterPath

A QPainterPath 对象可以构造成具有给定起点的空路径,或构造成副本为另一 QPainterPath 对象。一旦创建,就可以将直线和曲线添加到路径使用 lineTo (), arcTo (), cubicTo () 和 quadTo () 函数。直线和曲线的拉伸从 currentPosition () 到作为自变量传递的位置。

The currentPosition () 对于 QPainterPath 对象始终是最后添加子路径的结束位置 (或初始起点)。使用 moveTo () 函数以移动 currentPosition () 无需添加组件。 moveTo () 函数隐式开始新子路径,关闭先前子路径。开始新子路径的另一方式是调用 closeSubpath () 函数以关闭当前路径通过添加直线从 currentPosition () 回到路径的起始位置。注意:新路径将拥有 (0, 0) 作为其初始 currentPosition ().

QPainterPath 类还提供了几个方便函数,以将封闭子路径添加到描绘器路径: addEllipse (), addPath (), addRect (), addRegion () 和 addText ()。 addPolygon () 函数添加 unclosed 子路径。事实上,这些函数都是集合对于 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);
								

描绘器路径最初为空,当构建时。我们首先添加是封闭子路径的矩形。然后添加一起形成封闭子路径的 2 条贝塞尔曲线,即使它们未单独封闭。最后绘制整个路径。路径的填充是使用默认填充规则 Qt::OddEvenFill 。Qt 为填充路径提供了 2 种方法:

Qt::OddEvenFill Qt::WindingFill

Qt::FillRule 文档编制了解规则的定义。描绘器路径目前设置的填充规则可以检索使用 fillRule () 函数,和变更使用 setFillRule () 函数。

QPainterPath 信息

The QPainterPath 类提供了返回路径及其元素有关信息的一批函数。

The currentPosition () 函数返回最后添加子路径的终点 (或初始起点)。 elementAt () 函数可以用于检索各种子路径元素, number 对于元素可以检索使用 elementCount () 函数,和 isEmpty () 函数告诉是否此 QPainterPath 对象根本包含任何元素。

The controlPointRect () 函数返回包含此路径中所有点和控制点的矩形。此函数的计算显著更快于准确 boundingRect () 按浮点精度返回此描绘器路径的边界矩形。

最后, QPainterPath 提供 contains () 函数可以用于确定给定点或矩形是否在路径中,和 intersects () 函数确定给定矩形内的任何点是否也在此路径中。

QPainterPath 转换

出于兼容性原因,可能要求简化描绘器路径的表示: QPainterPath 提供 toFillPolygon (), toFillPolygons () 和 toSubpathPolygons () 函数以将描绘器路径转换成多边形。 toFillPolygon () 将描绘器路径作为一个单多边形返回,而后 2 函数返回多边形列表。

The toFillPolygons () 和 toSubpathPolygons () 函数的提供是因为绘制几个小多边形比绘制一个大多边形通常更快,即使绘制点的总数相同。两者之间的差异是 number 对于多边形由它们返回: toSubpathPolygons () 为每个子路径创建一个多边形,不管子路径相交 (即:边界矩形重叠),而 toFillPolygons () 函数只为重叠子路径创建一个多边形。

The toFillPolygon () 和 toFillPolygons () 函数首先将所有子路径转换成多边形,然后使用倒带技术以确保使用正确填充规则可以填充重叠子路径。注意,倒带会将额外直线插入多边形,所以填充多边形的轮廓不匹配路径轮廓。

范例

Qt 提供 描绘器路径范例 向量变形范例 ,位于 Qt 范例目录下。

The 描绘器路径范例 展示如何使用描绘器路径来构建用于渲染的复杂形状,并让用户实验填充和描边。 向量变形范例 展示如何使用 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 ().

成员函数文档编制

QPainterPath:: QPainterPath ()

构造空的 QPainterPath 对象。

QPainterPath:: QPainterPath (const QPointF & startPoint )

创建 QPainterPath 对象采用给定 startPoint 作为它的当前位置。

QPainterPath:: QPainterPath (const QPainterPath & path )

创建 QPainterPath 副本对象为给定 path .

另请参阅 operator= ().

QPainterPath:: ~QPainterPath ()

销毁此 QPainterPath 对象。

void QPainterPath:: addEllipse (const QRectF & boundingRectangle )

创建椭圆按指定 boundingRectangle 并将它作为封闭子路径添加到描绘器路径。

椭圆由顺时针曲线组成,开始并结束于 0 度 (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 (),和 合成 QPainterPath .

void QPainterPath:: addEllipse ( qreal x , qreal y , qreal width , qreal height )

这是重载函数。

创建在边界矩形内的椭圆定义按其左上角 ( x , y ), width and height ,并将它作为封闭子路径添加到描绘器路径。

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

这是重载函数。

创建椭圆位于 center 采用半径 rx and ry ,并将它作为封闭子路径添加到描绘器路径。

该函数在 Qt 4.4 引入。

void QPainterPath:: addPath (const QPainterPath & path )

添加给定 path to this 路径作为封闭子路径。

另请参阅 connectPath () 和 合成 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 () 和 合成 QPainterPath .

void QPainterPath:: addRect (const QRectF & rectangle )

添加给定 rectangle 到此路径作为封闭子路径。

The 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 (),和 合成 QPainterPath .

void QPainterPath:: addRect ( qreal x , qreal y , qreal width , qreal height )

这是重载函数。

添加矩形按位置 ( x , y ),采用给定 width and height ,作为封闭子路径。

void QPainterPath:: addRegion (const QRegion & region )

添加给定 region 到路径,通过将区域中的每个矩形作为单独封闭子路径添加到路径。

另请参阅 addRect () 和 合成 QPainterPath .

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

添加给定矩形 rect 带圆角到路径。

The xRadius and yRadius 自变量指定定义圆角矩形的椭圆半径。当 mode is Qt::RelativeSize , xRadius and yRadius 分别按矩形宽度和高度的一半的百分比指定,且应该在 0.0 到 100.0 范围内。

该函数在 Qt 4.4 引入。

另请参阅 addRect ().

void QPainterPath:: addRoundedRect ( qreal x , qreal y , qreal w , qreal h , qreal xRadius , qreal yRadius , Qt::SizeMode mode = ...)

这是重载函数。

添加给定矩形 x , y , w , h 带圆角到路径。

该函数在 Qt 4.4 引入。

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

添加给定 text 到此路径作为一组封闭子路径创建自 font 供给。定位子路径是使文本基线左端位于指定 point .

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 () 和 合成 QPainterPath .

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 之间。

正值角度意味着逆时针方向,而负值意味着顺时针方向。0 度位于 3 点钟位置。

注意,类似于其它百分比方法,百分比度量关于长度不是线性的,若路径中存在曲线。当存在曲线时,百分比自变量会被映射到贝塞尔方程的 t 参数。

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

创建就地弧形移动占据给定 rectangle at angle .

角度以度为单位指定。可以使用负值角度指定顺时针圆弧。

该函数在 Qt 4.2 引入。

另请参阅 moveTo () 和 arcTo ().

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

这是重载函数。

创建就地弧形移动占据 QRectF ( x , y , width , height ) at angle .

该函数在 Qt 4.2 引入。

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

创建弧形占据给定 rectangle ,开始于指定 startAngle 并延伸 sweepLength 度逆时针。

角度以度为单位指定。可以使用负值角度指定顺时针圆弧。

注意,此函数将弧形起点连接到当前位置,若尚未连接它们。添加弧形后,当前位置是弧形中的最后一点。要将线条绘回到第一点,使用 closeSubpath () 函数。

QLinearGradient myGradient;
QPen myPen;
QPointF center, startPoint;
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 (),和 合成 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 ().

void QPainterPath:: closeSubpath ()

闭合当前子路径通过绘制直线到子路径起始,自动开始新路径。新路径的当前点为 (0, 0)。

若子路径不包含任何元素,此函数什么都不做。

另请参阅 moveTo () 和 合成 QPainterPath .

void QPainterPath:: connectPath (const QPainterPath & path )

连接给定 path to this 路径,通过添加从此路径最后元素到给定路径第一元素的线条。

另请参阅 addPath () 和 合成 QPainterPath .

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

返回 true 若给定 point 在路径中,否则返回 false .

另请参阅 intersects ().

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

返回 true 若给定 rectangle 在路径中,否则返回 false .

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

返回 true 若给定路径 p 包含在当前路径中。返回 false 若当前路径的任何边缘和 p 相交。

路径的集操作将视路径为区域。非封闭路径被视为隐式封闭。

该函数在 Qt 4.3 引入。

另请参阅 intersects ().

QRectF QPainterPath:: controlPointRect () const

返回包含此路径中所有点和控制点的矩形。

此函数的计算显著更快于准确 boundingRect (),且返回矩形始终是超集对于矩形返回通过 boundingRect ().

另请参阅 boundingRect ().

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

添加立方贝塞尔曲线介于当前位置和给定 endPoint 使用控制点指定通过 c1 ,和 c2 .

添加曲线后,当前位置更新成曲线终点。

QLinearGradient myGradient;
QPen myPen;
QPainterPath myPath;
myPath.cubicTo(c1, c2, endPoint);
QPainter painter(this);
painter.setBrush(myGradient);
painter.setPen(myPen);
painter.drawPath(myPath);
								

另请参阅 quadTo () 和 合成 QPainterPath .

void QPainterPath:: cubicTo ( qreal c1X , qreal c1Y , qreal c2X , qreal c2Y , qreal endPointX , qreal endPointY )

这是重载函数。

添加 3 次方贝塞尔曲介于当前位置和终点 ( 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 的填充区域。可能扁平化贝塞尔曲线成线段,由于贝塞尔曲线交集的数值不稳定。

该函数在 Qt 4.3 引入。

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

返回 true 若任意点在给定 rectangle 相交路径;否则返回 false .

有交集,若组成矩形的任何线条与路径部分交叉,或者若矩形的任何部分与路径封闭的任何区域重叠。此函数遵守当前 fillRule 以确定认为什么在路径内。

另请参阅 contains ().

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

返回 true 若当前路径相交于任意点同给定路径 p 。也返回 true 若当前路径包含 (或被包含在) 任何部分的 p .

路径的集操作将视路径为区域。非封闭路径被视为隐式封闭。

该函数在 Qt 4.3 引入。

另请参阅 contains ().

bool QPainterPath:: isEmpty () const

返回 true 若此路径中没有元素,或者若唯一元素是 MoveToElement ;否则返回 false .

另请参阅 elementCount ().

qreal QPainterPath:: length () const

返回当前路径的长度。

void QPainterPath:: lineTo (const QPointF & endPoint )

添加直线从当前位置到给定 endPoint 。在绘制直线之后,当前位置被更新为在直线的终点。

另请参阅 addPolygon (), addRect (),和 合成 QPainterPath .

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

这是重载函数。

绘制线条从当前位置到点 ( x , y ).

void QPainterPath:: moveTo (const QPointF & point )

将当前点移到给定 point ,隐式启动新子路径并关闭先前子路径。

另请参阅 closeSubpath () 和 合成 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 )

添加 2 次方贝塞尔曲线介于当前位置和给定 endPoint 采用控制点指定通过 c .

在添加曲线后,当前点被更新到曲线终点。

另请参阅 cubicTo () 和 合成 QPainterPath .

void QPainterPath:: quadTo ( qreal cx , qreal cy , qreal endPointX , qreal endPointY )

这是重载函数。

添加 2 次方贝塞尔曲线介于当前点和端点 ( endPointX , endPointY ) 采用控制点指定通过 ( cx , cy ).

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

设置元素的 X 坐标和 Y 坐标在索引 index to x and y .

该函数在 Qt 4.2 引入。

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

将描绘器路径填充规则设为给定 fillRule 。Qt 为填充路径提供了 2 种方法:

Qt::OddEvenFill (默认) Qt::WindingFill

另请参阅 fillRule ().

QPainterPath QPainterPath:: simplified () const

返回此路径的简化版本。这隐含合并所有相交子路径,并返回包含不相交边缘的路径。还会合并连续平行线。简化路径将始终使用默认填充规则 Qt::OddEvenFill 。可能扁平化贝塞尔曲线成线段,由于贝塞尔曲线交集的数值不稳定。

该函数在 Qt 4.4 引入。

qreal QPainterPath:: slopeAtPercent ( qreal t ) const

返回路径的坡度按百分比 t 。自变量 t 必须在 0 和 1 之间。

注意,类似于其它百分比方法,百分比度量关于长度不是线性的,若路径中存在曲线。当存在曲线时,百分比自变量会被映射到贝塞尔方程的 t 参数。

QPainterPath QPainterPath:: subtracted (const QPainterPath & p ) const

返回路径是 p 的填充区域减去此路径的填充区域。

路径的集操作将视路径为区域。非封闭路径被视为隐式封闭。可能扁平化贝塞尔曲线成线段,由于贝塞尔曲线交集的数值不稳定。

该函数在 Qt 4.3 引入。

void QPainterPath:: swap ( QPainterPath & other )

交换描绘器路径 other 与此描绘器路径。此操作非常快且从不失败。

该函数在 Qt 4.8 引入。

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

将路径转换成多边形使用 QTransform matrix ,并返回多边形。

多边形的创建是通过首先将所有子路径转换成多边形,然后使用倒带技术以确保使用正确填充规则可以填充重叠子路径。

注意,倒带会将额外直线插入多边形,所以填充多边形的轮廓不匹配路径轮廓。

另请参阅 toSubpathPolygons (), toFillPolygons (),和 QPainterPath 转换 .

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

这是重载函数。

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

将路径转换成多边形列表使用 QTransform matrix ,并返回列表。

函数不同于 toFillPolygon () 函数,在此它创建数个多边形。提供它是因为绘制数个小多边形通常比绘制一个大多边形更快,即使总绘制点数相同。

toFillPolygons() 函数不同于 toSubpathPolygons () 函数,在此它为拥有重叠边界矩形的子路径创建唯一多边形。

toFillPolygon () 函数,此函数使用倒带技术以确保使用正确填充规则可以填充重叠子路径。注意,倒带会将额外直线插入多边形,所以填充多边形的轮廓不匹配路径轮廓。

另请参阅 toSubpathPolygons (), toFillPolygon (),和 QPainterPath 转换 .

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

这是重载函数。

QPainterPath QPainterPath:: toReversed () const

创建并返回路径的反转副本。

反转的是元素次序:若 QPainterPath 的组成是通过调用 moveTo (), lineTo () 和 cubicTo () 函数按指定次序,反转副本的组成将通过调用 cubicTo (), lineTo () 和 moveTo ().

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

将路径转换成多边形列表使用 QTransform matrix ,并返回列表。

此函数为每一子路径创建一个多边形,不管相交子路径 (即:重叠的边界矩形)。为确保正确填充这种重叠子路径,使用 toFillPolygons () 函数代替。

另请参阅 toFillPolygons (), toFillPolygon (),和 QPainterPath 转换 .

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

这是重载函数。

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

平移路径中的所有元素按 ( dx , dy ).

该函数在 Qt 4.6 引入。

另请参阅 translated ().

void QPainterPath:: translate (const QPointF & offset )

这是重载函数。

平移路径中的所有元素按给定 offset .

该函数在 Qt 4.6 引入。

另请参阅 translated ().

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

返回平移路径副本按 ( dx , dy ).

该函数在 Qt 4.6 引入。

另请参阅 translate ().

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

这是重载函数。

返回平移路径副本按给定 offset .

该函数在 Qt 4.6 引入。

另请参阅 translate ().

QPainterPath QPainterPath:: united (const QPainterPath & p ) const

返回路径是并集为此路径的填充区域和 p 的填充区域。

路径的集操作将视路径为区域。非封闭路径被视为隐式封闭。可能扁平化贝塞尔曲线成线段,由于贝塞尔曲线交集的数值不稳定。

该函数在 Qt 4.3 引入。

另请参阅 intersected () 和 subtracted ().

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

返回 true 若此描绘器路径不同于给定 path .

注意,比较路径可能涉及每个元素的比较,可能很慢对于复杂路径。

另请参阅 operator== ().

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

返回交集为此路径与 other 路径。

该函数在 Qt 4.5 引入。

另请参阅 intersected (), operator&= (), united (),和 operator| ().

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

交集此路径与 other 并返回此路径的引用。

该函数在 Qt 4.5 引入。

另请参阅 intersected (), operator& (),和 operator|= ().

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

返回并集为此路径与 other 路径。此函数相当于 operator|()。

该函数在 Qt 4.5 引入。

另请参阅 united (), operator+= (),和 operator- ().

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

联合此路径与 other ,并返回此路径的引用。这相当于 operator|=()。

该函数在 Qt 4.5 引入。

另请参阅 united (), operator+ (),和 operator-= ().

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

减去 other 路径从此路径的副本,并返回副本。

该函数在 Qt 4.5 引入。

另请参阅 subtracted (), operator-= (),和 operator+ ().

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

减去 other 从此路径,并返回此路径的引用。

该函数在 Qt 4.5 引入。

另请参阅 subtracted (), operator- (),和 operator+= ().

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

赋值给定 path 到此描绘器路径。

另请参阅 QPainterPath ().

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

移动赋值 other 到此 QPainterPath 实例。

该函数在 Qt 5.2 引入。

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

返回 true 若此描绘器路径等于给定 path .

注意,比较路径可能涉及每个元素的比较,可能很慢对于复杂路径。

另请参阅 operator!= ().

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

返回并集为此路径与 other 路径。

该函数在 Qt 4.5 引入。

另请参阅 united (), operator|= (), intersected (),和 operator& ().

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

联合此路径与 other 并返回此路径的引用。

该函数在 Qt 4.5 引入。

另请参阅 united (), operator| (),和 operator&= ().

相关非成员

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

写入给定描绘器 path 到给定 stream ,并返回引用为 stream .

另请参阅 序列化 Qt 数据类型 .

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

读取描绘器路径从给定 stream 到指定 path ,并返回引用为 stream .

另请参阅 序列化 Qt 数据类型 .