a.t*_*aby 5 qt qml qt-quick qtquick2 qt5.4
当我们Loader在QML中更改组件的来源时,有没有办法应用动画?例如,假设我有以下内容Loader:
Loader {
anchors.fill: parent
id: loader
}
Run Code Online (Sandbox Code Playgroud)
我设置时,我想要一个从左到右的动画 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"
}
Run Code Online (Sandbox Code Playgroud)
我的矩形.qml:
import QtQuick 2.0
Rectangle {
id: rect
color: "red"
width: 150
height: 150
}
Run Code Online (Sandbox Code Playgroud)