[Qt-qml] QML Picture slideshow with QAbstractItemModel
Kevin Trope
ktrope at awox.com
Fri May 27 18:03:17 CEST 2011
Hello,
I'm currently trying to write a picture slideshow in QML, where the URLs for the images are stored in a QAbstractListModel (with role "imagePath").
My approach is to have an Image item and to set the 'source' property of this Image to a new value when displaying the next, or previous, picture.
But I cannot figure out how to access the data model from a QML item, to check that my index is valid and to retrieve the "imagePath" value.
Sample from my code:
FocusScope {
id: slideshowScope
focus: true
property int currentIndex
property variant model
signal exitSlideshow()
signal playNext()
signal playPrevious()
function playImage(newModel, index) {
model = newModel;
console.log("playImage");
if ((index >= 0) && (index < model.count)) {
slideshowScope.focus = true;
slideshowScope.visible = true;
imageDisplay.source = model[index].imagePath;
currentIndex = index;
}
else {
exitSlideshow();
}
}
Image {
id: imageDisplay
width: parent.width; height: parent.height
fillMode: Image.PreserveAspectFit
}
Timer {
id: slideshowTimer
interval: 5000; running: slideshowScope.visible;
onTriggered: { playNext(); }
}
onPlayNext: {
slideshowScope.playImage(model,currentIndex+1);
}
onPlayPrevious: {
slideshowScope.playImage(model,currentIndex-1);
}
}
The model is set in another window, where a ListView has the model instantiated.
Model.count is undefined here.
Can someone give me a hand?
Cheers,
Kevin
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110527/b6b779d9/attachment-0001.html
More information about the Qt-qml
mailing list