QML: mid-sharp position position in SwipeView

I am trying to create a Parallax view based on a SwipeView element. The examples in the QML documentation illustrate how to achieve this with a ListView:

Image {
    id: background
    source: "background.png"
    fillMode: Image.TileHorizontally
    x: -list.contentX / 2
    width: Math.max(list.contentWidth, parent.width)
}

ListView {
    id: list
    anchors.fill: parent
    spacing: 20
    snapMode: ListView.SnapToItem
    orientation: ListView.Horizontal
    highlightRangeMode: ListView.StrictlyEnforceRange
    boundsBehavior: Flickable.StopAtBounds
    maximumFlickVelocity: 1000

    model: _some_cpp_list
    //Loader is used as a workaround for QTBUG-49224
    delegate: Loader {
        id: loaderDelegate
        source: "MyDelegate.qml"
        width: myScreen.width
        height: myScreen.height
        onLoaded: {
            loaderDelegate.item.logic = modelData
        }
    }
}

Now this works, but the instad from ListView I want to use SwipeView, since it requires less code to achieve the desired behavior:

SwipeView {
    id: list
    anchors.fill: parent
    spacing: 20
    Repeater {
        model: _some_cpp_list
        delegate: MyDelegate {
            logic: modelData
        }
    }

Is there a way to access the current "x" SwipeView position or shift offset for use on this line:

x: -list.contentX / 2?

The closest I have found so far is x: -swipeView.contentData[0].x / 2, but it causes transitions by elements, not a smooth transition.

+4
source share
1 answer

x- ListView, ListView. , , , , , Loader.

SwipeView, , , Translate QML. SwipeView ListView contentX SwipeView.contentItem. .:)

PS. . ParallaxView https://doc.qt.io/qt-5/qtquick-views-example.html.

+3

Source: https://habr.com/ru/post/1659020/


All Articles