首页 文章

是否可以在qml中制作循环滑动项目?

提问于
浏览
0

我在qml中使用swipeview . 我可以将物品从头到尾再刷回来 . 是否有可能从最终到第一次立即滑动?我没有在文档中找到任何信息 .

2 回答

  • 0

    你可以用PathView做到这一点 . Qt Quick Controls 2的Tumbler也可以wrap,因为它在内部使用 PathView .

  • 1

    您可以使用PathView . 一些代码如下:

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

相关问题