【问题标题】:Qt qml SwipeView change animation/transition speedQt qml SwipeView 改变动画/过渡速度
【发布时间】:2018-03-20 14:56:50
【问题描述】:

我正在使用 Qt 5.10,并且正在使用 SwipeView。我想改变滑动动画的速度,但在阅读了文档后我看不出怎么做。是否有一些解决方法可以做到这一点?

【问题讨论】:

  • 这是个好问题...我本来想说Component.onCompleted: contentItem.highlightMoveDuration = 10000(因为它是ListView),但这不起作用。也不会弄乱速度属性。

标签: qt qml qt5


【解决方案1】:

我尝试这样做的原因是,不知道为什么,滑动过渡动画非常慢(见下文) 这是我的代码:

ColumnLayout{
        anchors.fill: parent

        Item{
            id:modulecontainer

            Layout.fillHeight: true
            Layout.fillWidth: true

            SwipeView{
                id: moduleview
                anchors.fill: parent
                interactive: loggedUser.role==User.AdminRole
                clip: true
                orientation: Qt.Horizontal
                Item {
                    id: firstPage
                    Loader {
                        anchors.fill: parent
                        id:moduleLoader


                    }
                }
                Item {
                    id: secondPage
                    Rectangle{
                        anchors.fill: parent
                        color: "red"

                    }
                }
             }
           }
      }

我解决了这个问题,只是从 SwipeView 的源代码中获取contentItem 实现的代码:

  ....  
  SwipeView{
      id: moduleview
      ....
      contentItem: ListView {
                model: moduleview.contentModel
                interactive: moduleview.interactive
                currentIndex: moduleview.currentIndex

                spacing: moduleview.spacing
                orientation: moduleview.orientation
                snapMode: ListView.SnapOneItem
                boundsBehavior: Flickable.StopAtBounds

                highlightRangeMode: ListView.StrictlyEnforceRange
                preferredHighlightBegin: 0
                preferredHighlightEnd: 0
                highlightMoveDuration: 250
                //                    min:10

                maximumFlickVelocity: 4 * (moduleview.orientation === 
                Qt.Horizontal ? width : height)
            }
  }
  ....

结果:

不知道为什么这可以解决问题,但我正在分享以防其他人面临同样的问题。如果想要更快的动画速度,只需将 maximumFlickVelocity 因子从 4 替换为更大的值

【讨论】:

    猜你喜欢
    • 2020-02-20
    • 2019-11-25
    • 2012-03-17
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多