Hi Mark,

> I have a requirement where I need to be able to dynamically create a bunch
> of objects, and then be able to add them to a list of some sort so I can
> scroll through them. Each page can potentially be a different item with
> wildly different properties and functionality so coming up with a single
> delegate to cover all of these cases is not an option.

I can't comment on your problem with VisualItemModel, but an alternative way
to approach your requirement (if I understood it correctly) would be
to use a Loader
to implement factory pattern. Something like this:

    ListView {
        model: dataModel
        delegate: Loader {
            source: if (itemType == 0) "BookDelegate.qml"
                    else if (itemType == 1) "SongDelegate.qml"
                    else "MovieDelegate.qml"
        }
    }

    ListModel {
        id: dataModel
        ListElement {
            itemType: 0
            author: "William Shakespeare"
            title: "There's something wrong in the land of Denmark"
            pageCount: 654
        }
        ListElement {
            itemType: 1
            performer: "Michael Jackson"
            album: "Thriller"
            songTitle: "Beat it"
        }
        ListElement {
            itemType: 2
            movieTitle: "Raiders of the Lost Ark"
            director: "Steven Spielberg"
        }
    }

I doubt using the Loader to choose the delegate gives you too much
overhead unless the expression used to choose the delegate becomes
really complex.

cheers,
Juha
_______________________________________________
Qt-qml mailing list
Qt-qml@qt.nokia.com
http://lists.qt.nokia.com/mailman/listinfo/qt-qml

Reply via email to