Is it possible to make a cycle swipe items in qml?

家住魔仙堡 提交于 2019-12-13 04:41:28

问题


I use swipeview in qml. I can swipe items from first to final and back. Is it possible to swipe from final to first immediatly ? I didn't find any information in docs.


回答1:


You can do that with PathView. Qt Quick Controls 2's Tumbler can also be made to wrap because it uses PathView internally.




回答2:


You can use PathView. Some codes like this:

import QtQuick 2.0

Rectangle {
    width: 200
    height: 200

    ListModel {
        id: model
        ListElement {
            color: "red"
        }
        ListElement {
            color: "green"
        }
        ListElement {
            color: "blue"
        }
    }

    Component {
        id: delegate
        Rectangle {
            id: wrapper
            width: view.width
            height: view.height
            color: model.color

            Text {
                anchors.centerIn: parent
                font.pointSize: 26
                font.bold: true
                color: "white"
                text: index
            }
        }
    }

    PathView {
        id: view
        anchors.fill: parent
        snapMode: PathView.SnapOneItem
        highlightRangeMode: PathView.StrictlyEnforceRange
        currentIndex: -1
        model: model
        delegate: delegate
        path: Path {
            startX: -view.width / 2  // let the first item in left
            startY: view.height / 2  // item's vertical center is the same as line's

            PathLine {
                relativeX: view.width * view.model.count  // all items in lines
                relativeY: 0
            }
        }
    }
}


来源:https://stackoverflow.com/questions/49847767/is-it-possible-to-make-a-cycle-swipe-items-in-qml

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!