Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML StackView custom transition

I have gone through the Qt docs :Qt StackView yet still I can't figure out what am I doing wrong, because my code should produce fade in/out animation but what I got is just an instant blink between content. I hope my description is sufficient and clear.

StackView {
    id: stackView
    anchors.fill: parent
    delegate: StackViewDelegate {

        function transitionFinished(properties)
        {
            properties.exitItem.opacity = 1
        }

        property Component pushTransition: StackViewTransition {
            PropertyAnimation {
                target: enterItem
                property: "opacity"
                from: 0
                to: 1
                duration: 10
            }
            PropertyAnimation {
                target: exitItem
                property: "opacity"
                from: 1
                to: 0
                duration: 10
            }
        }
    }
    initialItem: Item {
        width: parent.width
        height: parent.height
        ListView {
            model: pageModel
            anchors.fill: parent
            delegate: AndroidDelegate {
                text: title
                onClicked: stackView.push(Qt.resolvedUrl(page))
            }
        }
    }
}
like image 883
Nadarian Avatar asked Oct 17 '25 13:10

Nadarian


2 Answers

I hit the same problem and asked their support - their example is wrong.

replace

property Component pushTransition: StackViewTransition {

with

pushTransition: StackViewTransition {

and it should work. pushTransition is actually a property on StackViewDelegate

I'm still trying to get the transitionFinished function to work becuase their example of that doesn't work either.

like image 183
Scott Avatar answered Oct 21 '25 11:10

Scott


This is working for me:

Window {
    id: mainWindowId
    width: 1280
    height: 800

    StackView {
       id: stackViewId
       anchors.fill: parent

      replaceEnter: Transition {
          PropertyAnimation{
              property: "opacity"
              from: 0
              to: 1
              duration: 300
          }
      }

      replaceExit: Transition {
          PropertyAnimation{
              property: "opacity"
              from: 1
              to: 0
              duration: 250
          }
      }

      initialItem: "yourStartingPage.qml"

    }
}

And for changing views:

stackViewId.replace("yourOtherPage.qml")
like image 28
NapoLion Avatar answered Oct 21 '25 11:10

NapoLion



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!