[Qt-qml] Loaders, Components and ListViews
Bartosh Wroblevksy
bartosh at live.com
Thu Dec 16 02:11:04 CET 2010
So I have this little example where data of a ListElement determines what component to load in a list view something like this
ListView {
ListModel {
id: aModel
ListElement {
name: "Bill Smith"
componentID: "redRectangle"
number: "555 3264"
}
ListElement {
name: "John Brown"
componentID:"brownRectangle"
number: "555 8426"
}
ListElement {
name: "Sam Wise"
componentID: "yellowRectangle"
number: "555 0473"
}
}
Component{
id: redRectangle
Rectangle{
width: 180; height: 200
color:"red"
}
}
Component{
id: brownRectangle
Rectangle{
width: 180; height: 200
color:"brown"
}
}
Component{
id: yellowRectangle
Rectangle{
width: 180; height: 200
color:"yellow"
}
}
width: 180; height: 600
model: aModel
delegate:Loader{
id:myLoader
sourceComponent: (componentID == "redRectangle")? redRectangle
: (componentID == "yellowRectangle"? yellowRectangle
: brownRectangle)
}
}
This all works fine and nice. But I was wondering if
sourceComponent: (componentID == "redRectangle")? redRectangle : (componentID == "yellowRectangle"? yellowRectangle : brownRectangle)
could perhaps be more generic without all the nested stuff. Something that would ideally look like this
sourceComponent: componentID
Any input would be great. Otherwise QML is fun, fun, fun.
Thanks,Bartosh
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20101215/18002aa9/attachment-0001.html
More information about the Qt-qml
mailing list