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



_______________________________________________
Qt-qml mailing list
[email protected]
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to