问题
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