QML - Vertical Swipe View?

允我心安 提交于 2019-12-14 02:04:52

问题


Is it possible to use the SwipeView in QML for vertical swiping rather than horizontal?

I'd like the Page contents of a SwipeView to float vertically, so a user has to scroll up and down to navigate between Pages.

If this is not possible how would I go about it?

UPDATE This functionality has been added to QT as seen here:

http://doc-snapshots.qt.io/qt5-dev/qml-qtquick-controls2-swipeview.html#orientation-prop


回答1:


After some more research I came up with a solution that works fine, using a ListView/ListModel/ListDelegate - posting it here for others who wants to achieve the same.

QML:

ListView {
    snapMode: ListView.SnapOneItem
    highlightRangeMode: ListView.StrictlyEnforceRange

    anchors {
        top: parent.top
        bottom: parent.bottom
        left: parent.left
        right: parent.right
    }

    model: ListModel {
        id: listModel

        ListElement {
            text: "1"
        }
        ListElement {
            text: "2"
        }
        ListElement {
            text: "3"
        }
    }

    delegate: Page {
        width:  ListView.view.width
        height: ListView.view.height

        Text {
            anchors.centerIn: parent
            text: model.text
        }
    }
}


来源:https://stackoverflow.com/questions/39507444/qml-vertical-swipe-view

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