QPainterPathStroker Class
QPainterPathStroker 类用于根据给定的绘制路径生成可填充的轮廓。更多内容...
| 头文件: | #include <QPainterPathStroker> |
| CMake: | find_package(Qt6 REQUIRED COMPONENTS Gui) target_link_libraries(mytarget PRIVATE Qt6::Gui) |
| qmake: | QT += gui |
- 所有成员的列表,包括继承的成员
- QPainterPathStroker 属于绘图类。
公共函数
| QPainterPathStroker() | |
| QPainterPathStroker(const QPen &pen) | |
| ~QPainterPathStroker() | |
| Qt::PenCapStyle | capStyle() const |
| QPainterPath | createStroke(const QPainterPath &path) const |
| qreal | curveThreshold() const |
| qreal | dashOffset() const |
| QList<qreal> | dashPattern() const |
| Qt::PenJoinStyle | joinStyle() const |
| qreal | miterLimit() const |
| void | setCapStyle(Qt::PenCapStyle style) |
| void | setCurveThreshold(qreal threshold) |
| void | setDashOffset(qreal offset) |
| void | setDashPattern(Qt::PenStyle style) |
| void | setDashPattern(const QList<qreal> &dashPattern) |
| void | setJoinStyle(Qt::PenJoinStyle style) |
| void | setMiterLimit(qreal limit) |
| void | setWidth(qreal width) |
| qreal | width() const |
详细说明
通过调用createStroke()函数,并将给定的QPainterPath 作为参数传递,即可创建一个代表给定路径轮廓的新绘制路径。随后可对该新创建的绘制路径进行填充,以绘制原始绘制路径的轮廓。
您可以使用以下函数控制轮廓的各种设计属性(宽度、端点样式、连接样式和虚线模式):
setDashPattern() 函数既接受 `Qt::PenStyle ` 对象,也接受模式的列表表示形式作为参数。
此外,您还可以通过setCurveThreshold()函数指定曲线的阈值,从而控制绘制曲线时的细分程度。默认阈值是一个经过精心调整的数值(0.25),通常您无需对其进行修改。不过,您可以通过降低该数值来使曲线外观更加平滑。
您还可以通过 `setMiterLimit()` 函数控制生成的轮廓的倒角限制。倒角限制描述了倒角连接可以从每个连接点延伸多远。该限制以宽度为单位指定,因此按像素计算的倒角限制为 `miterlimit * width`。此值仅在连接样式为 `Qt::MiterJoin` 时使用。
由createStroke() 函数生成的绘制路径仅应用于勾勒给定的绘制路径轮廓。否则可能会导致意外行为。生成的轮廓还需遵循Qt::WindingFill 规则,该规则默认已启用。
成员函数文档
QPainterPathStroker::QPainterPathStroker()
创建一个新的抽动器。
[explicit] QPainterPathStroker::QPainterPathStroker(const QPen &pen)
基于pen 创建一个新的Stroker。
[noexcept] QPainterPathStroker::~QPainterPathStroker()
摧毁了自慰器。
Qt::PenCapStyle QPainterPathStroker::capStyle() const
返回生成的轮廓的字顶样式。
另请参阅 setCapStyle()。
QPainterPath QPainterPathStroker::createStroke(const QPainterPath &path) const
生成一条新路径,该路径是一个可填充区域,代表给定path 的轮廓。
轮廓的各项设计特征基于描边器的属性:width()、capStyle()、joinStyle()、dashPattern()、curveThreshold() 以及miterLimit()。
生成的路径仅应用于勾勒给定的绘制路径。否则可能会导致意外行为。生成的轮廓还需遵循Qt::WindingFill 规则,该规则默认已启用。
qreal QPainterPathStroker::curveThreshold() const
返回生成的轮廓的曲线平滑阈值。
另请参阅 setCurveThreshold()。
qreal QPainterPathStroker::dashOffset() const
返回生成的轮廓的破折号偏移量。
另请参阅 setDashOffset()。
QList<qreal> QPainterPathStroker::dashPattern() const
返回生成的轮廓所采用的破折号样式。
另请参阅 setDashPattern()。
Qt::PenJoinStyle QPainterPathStroker::joinStyle() const
返回生成的轮廓的连接样式。
另请参阅 setJoinStyle()。
qreal QPainterPathStroker::miterLimit() const
返回生成的轮廓的斜切限制。
另请参阅 setMiterLimit()。
void QPainterPathStroker::setCapStyle(Qt::PenCapStyle style)
将生成的轮廓的端点样式设置为style 。如果设置了虚线图案,则该图案的每个线段均采用端点样式style 。
另请参阅 capStyle()。
void QPainterPathStroker::setCurveThreshold(qreal threshold)
指定曲线平滑度threshold ,用于控制生成的轮廓曲线绘制时的精细程度。
默认阈值是一个经过精心调整的数值(0.25),通常无需修改。不过,您可以通过降低该值来使曲线外观更平滑。
另请参阅 curveThreshold()。
void QPainterPathStroker::setDashOffset(qreal offset)
将生成的轮廓的破折号偏移量设置为offset 。
有关破折号偏移量的说明,请参阅QPen::setDashOffset() 的文档。
另请参阅 dashOffset()。
void QPainterPathStroker::setDashPattern(Qt::PenStyle style)
将生成的轮廓的破折号样式设置为style 。
另请参阅 dashPattern()。
void QPainterPathStroker::setDashPattern(const QList<qreal> &dashPattern)
将生成的轮廓的虚线样式设置为dashPattern 。此函数允许指定自定义的虚线样式。
列表中的每个元素包含笔画中破折号和空格的长度,从第一个元素中的第一个破折号开始,第二个元素中的第一个空格开始,随后每对元素交替指定破折号和空格。
该列表可以包含奇数个元素,在这种情况下,当图案重复时,最后一个元素的长度将延长为第一个元素的长度。
这是一个重载函数。
void QPainterPathStroker::setJoinStyle(Qt::PenJoinStyle style)
将生成的轮廓的连接样式设置为style 。
另请参阅 joinStyle()。
void QPainterPathStroker::setMiterLimit(qreal limit)
将生成的轮廓的倒角限制设置为limit 。
倒角限制描述了倒角接合处可以从每个接合点延伸多远。该限制以当前设置的宽度为单位进行指定。因此,按像素计算的倒角限制为miterlimit * width 。
仅当接缝样式为Qt::MiterJoin 时,才会使用此值。
另请参阅 miterLimit()。
void QPainterPathStroker::setWidth(qreal width)
将生成的轮廓绘制路径的宽度设置为width 。
生成的轮廓将向给定输入路径原始轮廓的两侧各延伸约width 的50%。
另请参阅 width()。
qreal QPainterPathStroker::width() const
返回生成的轮廓的宽度。
另请参阅 ` setWidth()`。
© 2026 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.