VectorImage QML Type
加载矢量图像文件并将其显示在Qt Quick 场景中。更多
| Import Statement: | import QtQuick.VectorImage |
| Since: | Qt 6.8 |
| Inherits: |
属性
- animations
(since 6.10)- animations.loops : int
(since 6.10) - animations.paused : bool
(since 6.10)
- animations.loops : int
- assumeTrustedSource : bool
(since 6.10) - asynchronousShapes : bool
(since 6.11) - fillMode : enumeration
- preferredRendererType : enumeration
- source : url
详细说明
VectorImage 可用于加载矢量图像文件,并将其显示为Qt Quick 场景中的一个项目。
它目前支持SVG 文件格式。此外,还可通过将assumeTrustedSource 属性设置为 true 并将插件从 Qt Lottie Animation模块中的插件,即可启用 Lottie 支持。
注: 这与通过Image 元素加载矢量图像文件的方法相辅相成:Image 按要求的尺寸创建图像的光栅版本。VectorImage 会创建一个代表图像的Qt Quick 场景。这意味着生成的项目可以缩放和旋转而不会降低质量,而且通常比光栅化版本消耗更少的内存。
属性文档
animations group
如果图像中包含动画,这些属性可用于控制图像中的动画。
可将paused 属性设置为 true,以暂时停止所有动画。当该属性重置为false 时,动画将恢复原样。默认情况下,该属性为false 。
loops 属性定义了文档中动画的重复次数。默认情况下,此属性为 1。源图像中设置为无限循环的任何动画都不会受此属性影响。要使文档中的所有动画无限重复,可将loops 属性设置为Animation.Infinite 。
这些属性在 Qt 6.10 中引入。
assumeTrustedSource : bool [since 6.10]
在加载受信任的源文件时,将此设置为 "true",可扩展对某些功能的支持,而这些功能在不受控制的情况下可能是不安全的。特别是对于 SVG,这映射到AssumeTrustedSource option 。
设置为 true 时,如果 Lottie 格式插件可用,VectorImage 还将尝试使用该插件加载图片。更多信息请参见 Qt Lottie Animation了解更多信息。
默认情况下,该属性为false 。
此属性在 Qt 6.10 中引入。
另请参阅 svgtoqml和lottietoqml。
asynchronousShapes : bool [since 6.11]
此属性控制VectorImage 为表示图像而构建的 Quick 场景中Shape 项的 {QtQuick.Shapes::Shape::asynchronous}{asynchronous} 属性。
将此属性设置为true 将把形状渲染处理的 CPU 部分卸载到独立的工作线程中。这可以提高 CPU 利用率和用户界面响应速度。
默认情况下,此属性为false 。
此属性在 Qt 6.11 中引入。
fillMode : enumeration
该属性定义了如果VectorImage 的宽度和高度与内容的隐含大小不同时会发生的情况。
| 常数 | 说明 |
|---|---|
VectorImage.NoResize | 内容仍按输入提供的尺寸渲染。 |
VectorImage.Stretch | 内容按比例缩放,以匹配VectorImage 的宽度和高度(默认值)。 |
VectorImage.PreserveAspectFit | 缩放内容以适应VectorImage 的边界,同时保持宽高比。内容的实际边界矩形有时会小于VectorImage 项目。 |
VectorImage.PreserveAspectCrop | 内容按比例填充VectorImage 项目,同时保持宽高比。内容的实际边界有时会大于VectorImage 项目。 |
preferredRendererType : enumeration
请求使用特定的后端来渲染VectorImage 中的图形。
| 常量 | 描述 |
|---|---|
VectorImage.GeometryRenderer | 等同于 Shape.GeometryRenderer。该后端会平整曲线并对结果进行三角化处理。除非启用多重取样功能,否则它将生成有别名的结果,并且在缩放项目时可能会看到曲线扁平化。 |
VectorImage.CurveRenderer | 等同于 Shape.CurveRenderer。使用此后端,曲线将在 GPU 上渲染,并内置抗锯齿功能。通常会带来更好的视觉效果,但会对性能造成一定影响。 |
默认值为VectorImage.GeometryRenderer 。
source : url
该属性包含要加载的矢量图像文件的 URL。
VectorImage 目前支持SVG 文件格式。此外,将assumeTrustedSource 属性设置为 true 并将插件从 Qt Lottie Animation模块中包含该插件。
© 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.