QPainterPathStroker Class
QPainterPathStroker 类用于为给定的绘制路径生成可填充的轮廓。更多
Header: | #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 创建新的冲程。
[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 。
生成的轮廓将向给定输入路径原始轮廓的两侧各延伸约 50%,width 。
另请参阅 width() 。
qreal QPainterPathStroker::width() const
返回生成轮廓的宽度。
另请参阅 setWidth()。
© 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.