PathAttribute QML Type
指定如何在路径的给定位置设置属性。更多
Import Statement: | import QtQuick |
属性
详细说明
PathAttribute 对象允许为路径上的各个点指定由名称和值组成的属性。这些属性作为附加属性暴露给委托。路径上任何特定点的属性值都是从该点周围的 PathAttributes 中推算出来的。
下面的示例显示了一条路径,路径顶部的项目缩放为 30%,不透明度为 50%,底部的项目缩放为 100%,不透明度为 100%。请注意使用PathView.iconScale和PathView.iconOpacity附加属性来设置委托的缩放比例和不透明度。
import QtQuick Rectangle { width: 240; height: 200 Component { id: delegate Item { width: 80; height: 80 scale: PathView.iconScale opacity: PathView.iconOpacity Column { Image { anchors.horizontalCenter: nameText.horizontalCenter; width: 64; height: 64; source: icon } Text { id: nameText; text: name; font.pointSize: 16 } } } } PathView { anchors.fill: parent model: ContactModel {} delegate: delegate path: Path { startX: 120; startY: 100 PathAttribute { name: "iconScale"; value: 1.0 } PathAttribute { name: "iconOpacity"; value: 1.0 } PathQuad { x: 120; y: 25; controlX: 260; controlY: 75 } PathAttribute { name: "iconScale"; value: 0.3 } PathAttribute { name: "iconOpacity"; value: 0.5 } PathQuad { x: 120; y: 100; controlX: -20; controlY: 75 } } } } (有关上述 ContactModel 使用的 ContactModel.qml 规范,请参阅PathView 文档)。 |
另请参阅 Path 。
属性文档
name : string |
value : real |
该属性包含属性的值。
指定的值可用于影响路径上项目的视觉外观。例如,下面的路径指定了一个名为itemRotation 的属性,该属性在路径开始时的值为0,在路径结束时的值为 90。
Path { startX: 0 startY: 0 PathAttribute { name: "itemRotation"; value: 0 } PathLine { x: 100; y: 100 } PathAttribute { name: "itemRotation"; value: 90 } }
在委托中,我们可以将旋转属性绑定到为该属性创建的附加属性 PathView.itemRotation。
Rectangle { width: 10; height: 10 rotation: PathView.itemRotation }
当每个项目沿路径定位时,它将相应地旋转:位于路径起点的项目将不旋转,位于路径终点的项目将旋转 90 度,位于路径中段的项目将旋转 45 度。
© 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.