[Qt-qml] QML Picture slideshow with QAbstractItemModel

vineeth nvineeth at gmail.com
Sun May 29 08:35:13 CEST 2011


Hi,
  You can find the example of using a qabstractlistmodel here :
http://doc.trolltech.com/4.7.1/declarative-modelviews-abstractitemmodel.html
  You can access the imagePath as model.imagePath, i.e in Image element,
source:model.imagePath should set the path.
HTH,
--vineeth



On Fri, May 27, 2011 at 9:33 PM, Kevin Trope <ktrope at awox.com> wrote:

>  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
>
>
>
>
> __________ Information from ESET NOD32 Antivirus, version of virus
> signature database 6158 (20110527) __________
>
> The message was checked by ESET NOD32 Antivirus.
>
> http://www.eset.com
>
> _______________________________________________
> Qt-qml mailing list
> Qt-qml at qt.nokia.com
> http://lists.qt.nokia.com/mailman/listinfo/qt-qml
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20110529/683c6591/attachment-0001.html 


More information about the Qt-qml mailing list