考虑下面的一段代码,它获取一个 RSS 提要,然后将其中的图像显示为永远循环的幻灯片:
import QtQuick 2.2
import QtQuick.XmlListModel 2.0
Rectangle {
id: window
color: "black"
width: 800
height: 480
PathView {
anchors.fill: parent
highlightRangeMode: PathView.StrictlyEnforceRange
preferredHighlightBegin: 0.5
preferredHighlightEnd: 0.5
highlightMoveDuration: 500
snapMode: PathView.SnapOneItem
pathItemCount: 3 // only show previous, current, next
path: Path { // horizontal
startX: -width; startY: height/2
PathLine{x: width*2; y: height/2}
}
model: XmlListModel {
source: "http://feeds.bbci.co.uk/news/business/rss.xml"
query: "/rss/channel/item"
namespaceDeclarations: "declare namespace media = 'http://search.yahoo.com/mrss/';"
XmlRole { name: "image"; query: "media:thumbnail/@url/string()" }
}
delegate: Image {
width: …Run Code Online (Sandbox Code Playgroud)