我在qml中使用swipeview。我可以将项目从第一个滑动到最后一个,然后再返回。是否可以立即从最后滑动到第一?我在文档中没有找到任何信息。
您可以使用 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
}
}
}
}