本页内容

PathInterpolator QML Type

指定如何沿路径手动制作动画。更多...

Import Statement: import QtQuick

属性

详细说明

PathInterpolator 为路径上的特定progress 提供x 、y 和angle 信息。

在下面的示例中,我们将一个绿色矩形沿贝塞尔路径进行动画处理。

import QtQuick

Rectangle {
    width: 400
    height: 400

    PathInterpolator {
        id: motionPath

        path: Path {
            startX: 0; startY: 0

            PathCubic {
                x: 350; y: 350

                control1X: 350; control1Y: 0
                control2X: 0; control2Y: 350
            }
        }

        NumberAnimation on progress { from: 0; to: 1; duration: 2000 }
    }

    Rectangle {
        width: 50; height: 50
        color: "green"

        //bind our attributes to follow the path as progress changes
        x: motionPath.x
        y: motionPath.y
        rotation: motionPath.angle
    }
}

属性文档

angle : real [read-only]

该属性保存了路径在progress 处的切线角度。

角度以顺时针方向表示,3 点钟位置为 0 度。

path : Path

该属性存储待插值的路径。

有关定义路径的更多信息,请参阅Path 文档。

progress : real

该属性保存沿路径的当前进度。

PathInterpolator 的典型用法是设置进度(通常通过NumberAnimation 实现),并读取相应的x、y和角度值(通常通过与这些值的绑定实现)。

进度范围为 0.0 到 1.0。

x : real [read-only]

y : real [read-only]

这些属性存储了路径在progress 上的位置。

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