【问题标题】:QML StackView custom transitionQML StackView 自定义过渡
【发布时间】:2014-04-01 11:35:14
【问题描述】:

我已经浏览了 Qt 文档:Qt StackView,但我仍然无法弄清楚我做错了什么,因为我的代码应该产生淡入/淡出动画,但我得到的只是内容之间的瞬间闪烁。我希望我的描述是充分和清楚的。

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))
            }
        }
    }
}

【问题讨论】:

    标签: qt qml transitions stackview


    【解决方案1】:

    我遇到了同样的问题并请求他们的支持 - 他们的例子是错误的。

    替换

    property Component pushTransition: StackViewTransition {
    

    pushTransition: StackViewTransition {
    

    它应该可以工作。 pushTransition 实际上是StackViewDelegate上的一个属性

    我仍在尝试让 transitionFinished 函数工作,因为他们的示例也不起作用。

    【讨论】:

    • 实际上,我发现 transitionFinished 在我的情况下工作。
    【解决方案2】:

    动画的持续时间为 10 毫秒,即 1/100 秒。

    【讨论】:

    • 好吧,我尝试了不同的值:1k、10k、100k 仍然没有结果
    【解决方案3】:

    这对我有用:

    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"
    
        }
    }
    

    对于改变视图:

    stackViewId.replace("yourOtherPage.qml")
    

    【讨论】:

      猜你喜欢
      • 2012-12-11
      • 1970-01-01
      • 2013-11-23
      • 2014-03-04
      • 2020-03-12
      • 2012-06-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多