Qt Quick Shapes QML Types

要使用本模块中的类型,请使用以下代码行导入该模块:

import QtQuick.Shapes

Qt Quick Shapes 提供了一系列工具,用于在Qt Quick 场景中绘制任意形状。Shapes 可以通过lines 和curves 等定义子形状的基本构建块来构建。随后,可以为子形状填充纯色或渐变色,并定义轮廓线。

Qt Quick Shapes 还支持更高层次的路径元素类型,例如text 和SVG path descriptions 。当前支持的元素类型包括:PathMove 、PathLine 、PathQuad 、PathCubic 、PathArc 、PathText 和PathSvg 。

Qt Quick “形状”功能会对形状进行三角剖分,并在 GPU 上渲染相应的三角形。因此,修改元素的控制点会导致受影响路径重新进行三角剖分,这会带来一定的性能开销。 此外,曲线在渲染前会被展平,因此如果对形状应用过高的缩放比例,可能会出现可见的伪影,即曲线被表示为一系列较小的直线。

注意:默认情况下, Qt Quick 中的“形状”功能依赖多采样进行抗锯齿处理。可通过QSurfaceFormat 中的相应设置,为整个应用程序或窗口启用此功能。也可以仅针对该形状启用此功能,方法是将layer.enabled 属性设置为true,然后调整layer.samples 属性。 在后一种情况下,多采样不会应用于整个场景,而是通过一个中间的屏外缓冲区来渲染该形状。此外,还可以将preferredRendererType 属性设置为Shape.CurveRenderer 。此模式内置了抗锯齿功能,通常能以更高的质量渲染形状,但会带来一定的性能开销。

如需了解更多信息,请参阅“形状”示例,其中展示了如何实现不同类型的形状、填充和描边;“天气预报”示例则展示了形状在用户界面中可能发挥作用的各种方式。

ConicalGradient

锥形渐变

LinearGradient

线性渐变

RadialGradient

径向渐变

Shape

渲染路径

ShapeGradient

“形状”填充渐变的基本类型

ShapePath

描述路径及其相关的描边和填充属性

© 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.