【发布时间】:2017-02-19 12:43:42
【问题描述】:
如何在 QML 中的 Pathview 元素到达模型中的最后一个元素时停止移动(如列表视图和网格视图默认行为)。即,我不想要循环移动。
在下面的代码中,如果我们在第一个(“第一个”)项目后向右滑动,最后一个(“最后一个”)将显示(然后是“Jane Doe”)。可以做些什么来阻止第一次向右进一步滑动到达并在到达最后一项时进一步向左滑动。到达第一项或最后一项时应停止
import QtQuick 2.5
import QtQuick.Window 2.2
Window {
visible: true
width: 640
height: 480
title: qsTr("Hello World")
ListModel {
id:contactModel
ListElement {
name: "first"
icon: "pic.png"
}
ListElement {
name: "Jane Doe"
icon: "pic.png"
}
ListElement {
name: "John Smith"
icon: "pic.png"
}
ListElement {
name: "Bill Jones"
icon: "pic.png"
}
ListElement {
name: "Jane Doe"
icon: "pic.png"
}
ListElement {
name: "John Smith"
icon: "pic.png"
}
ListElement {
name: "Bill Jones"
icon: "pic.png"
}
ListElement {
name: "Jane Doe"
icon: "pic.png"
}
ListElement {
name: "last"
icon: "pic.png"
}
}
Component {
id: delegate
Column {
id: wrapper
Image {
anchors.horizontalCenter: nameText.horizontalCenter
width: 64; height: 64
source: icon
}
Text {
id: nameText
text: name
font.pointSize: 5
color: wrapper.PathView.isCurrentItem ? "red" : "black"
}
}
}
PathView {
anchors.fill: parent
model: contactModel
delegate: delegate
snapMode:PathView.SnapOneItem
path: Path {
startX: 0; startY: 100
PathLine { x: 640; y: 400; }
}
}
}
【问题讨论】:
-
请包含您目前编写的代码。您提供的详细信息越多,您可能收到的答案就越多。检查FAQ 和How to ask。
标签: qt qml qt-creator