当我们更改 QML 中的 Loader
组件的源时,有什么方法可以应用动画吗?
例如,假设我有以下Loader
:
Loader {
anchors.fill: parent
id: loader
}
当我设置loader.source =“content.qml”时,我想要一个从左到右的动画
感谢您的帮助。
最佳答案
这是一种方法:
import QtQuick 2.4
import QtQuick.Window 2.0
Window {
id: window
width: 400
height: 400
visible: true
Loader {
id: loader
onSourceChanged: animation.running = true
NumberAnimation {
id: animation
target: loader.item
property: "x"
from: 0
to: window.width - loader.item.width
duration: 1000
easing.type: Easing.InExpo
}
}
// Replace this with some other action that changes the source.
Component.onCompleted: loader.source = "MyRectangle.qml"
}
MyRectangle.qml:
import QtQuick 2.0
Rectangle {
id: rect
color: "red"
width: 150
height: 150
}
关于qt - loader.source 更改时 Qml 加载器的动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31219063/