Add transitions in stack layout
This commit is contained in:
1 parent
4da0e784ca
commit
51d2e7be05
4 files changed
+55
-1
No files matched your search
@@ -0,0 +1,52 @@
|
||||
import QtQuick
|
||||
import QtQuick.Layouts
|
||||
|
||||
StackLayout {
|
||||
id: root
|
||||
property int previousIndex: 0
|
||||
property var items: children
|
||||
property Item previousItem: items[previousIndex]
|
||||
property Item currentItem: items[currentIndex]
|
||||
|
||||
Component.onCompleted: {
|
||||
previousIndex = currentIndex
|
||||
|
||||
for(var i = 1; i < count; ++i) {
|
||||
children[i].opacity = 0
|
||||
}
|
||||
}
|
||||
|
||||
Component {
|
||||
id: crossFader
|
||||
ParallelAnimation {
|
||||
property Item fadeOutTarget
|
||||
property Item fadeInTarget
|
||||
|
||||
NumberAnimation {
|
||||
target: fadeOutTarget
|
||||
property: "opacity"
|
||||
to: 0
|
||||
duration: 300
|
||||
}
|
||||
|
||||
NumberAnimation {
|
||||
target: fadeInTarget
|
||||
property: "opacity"
|
||||
to: 1
|
||||
duration: 300
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onCurrentIndexChanged: {
|
||||
items = root.children
|
||||
|
||||
if(previousItem && currentItem && (previousItem != currentItem)) {
|
||||
previousItem.visible = false
|
||||
currentItem.visible = true
|
||||
var crossFaderAnim = crossFader.createObject(parent, {fadeOutTarget: previousItem, fadeInTarget: currentItem})
|
||||
crossFaderAnim.restart()
|
||||
}
|
||||
previousIndex = currentIndex
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user