在本页

Easing QML Type (Singleton)

提供对缓和枚举和便捷 API 的访问。更多

Import Statement: import QtQml
Since: Qt 6.11

注意:此类型是 QML 单例。在 QML 引擎中该类型只有一个实例。

详细描述

Easing 单例提供对Easing 枚举的访问,该枚举通常由animations 使用。它还提供valueForProgress 函数作为方便的 API:

    Rectangle {
        id: rect
        width: 100
        height: 100
        anchors.centerIn: parent
        color: "red"
        opacity: 0
    }

    FrameAnimation {
        id: frameAnimation
        running: true

        property real elapsed // In seconds.
        readonly property real duration: 2 // Two seconds.

        onTriggered: {
            elapsed += frameTime
            // Loop once we reach the duration.
            if (elapsed > duration)
                elapsed = 0

            // Increase the opacity from 0 slowly at first, then quickly.
            rect.opacity = Easing.valueForProgress(Easing.InQuart, elapsed / duration)
        }
    }

该函数的目的是提供一种沿给定曲线缓和值的便捷方法。对于更高级的曲线,请使用easingCurve 值类型。

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