动态更改动画中使用的 from/to 个值

Dynamically change from/to values used in animations

假设我有以下代码:

Rectangle {
  id: rect

  property int minVal : 0
  property int maxVal : 10
  property int duration: 1000

  SequentialAnimation {
    loops: Animation.infinite
    NumberAnimation {
       target: rect; property: "x"
       from: minVal;  to: maxVal
       duration: duration
    }
    NumberAnimation {
       target: rect; property: "x"
       from: maxVal;  to: minVal
       duration: duration
    }
  }
}

然后,我将这个对象的 minValmaxValduration 属性连接到滑块,这样我就可以玩这个效果了。

有没有办法强制动画使用 min/maxVal 的新值?

目前,动画初始化时出现的 minVal/maxVal 值似乎会 "baked" 进入动画,无法强制这些值 recalculated/rebaked 以后

以前,每次需要进行其中一项更改时,我都可以扔掉整个 QML canvas。但是在这种情况下,它不太实用,所以我想知道是否还有其他选择?

我找不到在这些值中 'bake' 的方法。至少对我来说,这符合我的预期:

Button {
    id: but
    property int count: 0
    property int minX: 0
    property int maxX:  1000

    text: 'start' + x

    onCountChanged: {
        minX += 10
        maxX -= 10
    }

    onClicked: ani.start()
}

SequentialAnimation {
    id: ani
    NumberAnimation {
        target: but
        property: 'x'
        from: but.minX
        to: but.maxX
    }
    ScriptAction {
        script: { but.count += 1 }
    }
}

我尽可能地尝试避免可能以某种方式烘焙的绑定。
我错过了你的问题吗?