在本页

easingCurve QML Value Type

表示缓和曲线的值。更多

Since: Qt 6.11

详细说明

easingCurve 类型是一个带有定义easing curve 属性的值:

  • enumeration type
  • real amplitude
  • real overshoot
  • real period
  • list<real> bezierCurve

例如,在使用FrameAnimation 制作自定义动画时,或在任何需要沿给定曲线缓和数值的使用情况下,它都非常有用。

要创建easingCurve 值,请将QtQml (或QtQuick )导入命名空间:

import QtQml as QtQml

然后,使用new 创建一个实例:

        readonly property easingCurve easingCurve: Easing.InQuart

下面的示例与Easing 文档中描述的示例类似:

    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.
        readonly property easingCurve easingCurve: Easing.InQuart

        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 = inQuartCurve.valueForProgress(elapsed / duration)
        }
    }

也可以通过结构化值类型语法创建easingCurve

    readonly property easingCurve inElasticCurve: ({
        type: Easing.InElastic,
        amplitude: 4,
        period: 3
    })

当与 C++ 集成时,请注意任何从 C++ 传入 QML 的 QEasingCurve 值都会自动转换成easingCurve 值。当easingCurve 值传入 C++ 时,它会自动转换成QEasingCurve 值。

默认构造的easingCurve 等于new QtQml.easingCurve(QtQml.Easing.Linear)

另请参阅 QML 值类型

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