[Qt-qml] Looking for a working example: Dynamically created items with bound properties

Adriano Rezende adriano.rezende at openbossa.org
Tue Sep 7 19:40:47 CEST 2010


Hi,

Instead of creating the items using Qt.createQmlObject with a huge
code string, I think it's more elegant to declare your component and
use YourComponent.createObject to achieve the same result.

Like below:

Component {
    id: flickableItem
    Rectangle {
        property string text
        radius: 5
        width: 75
        height: 20
        color: buttonBody.color
        Text{
            text: parent.text
            color: "white"
            anchors.centerIn: parent
        }
    }
}

var item = flickableItem.createObject(dynamicflickableListDummy.contentItem);
item.text = "...";

You can use a trick to avoid creating the binding object yourself; you
can see that color is already binded to buttonBody. This will do the
binding when the instance is created in the flickable context.

Also, try to use Qt 4.7 RC1, the dynamicflickableListDummy.contentItem
should work.

I see that you are layouting your flickable items like a ListView. If
the idea is simple as that it's better to use a ListView with a model
instead of a Flickable.


Br,
Adriano



More information about the Qt-qml mailing list