[Qt-qml] Models and binding values

alan.westbrook at nokia.com alan.westbrook at nokia.com
Thu Jul 22 20:39:35 CEST 2010


Hi,

The docs mention it, but I can't seem to get it to work.

I am trying to get items in a list to bind to values from the model that is assigned.

Here are some things I have tried:


    Component {

        id: bardelegate

        Rectangle {

                ...

            Rectangle {

                id: self

                ...

                opacity: selected ? 0.6 : 1.0


                property bool itemSelected: model.selected

                onItemSelectedChanged: opacity = itemSelected ? 0.6 : 1.0

                Binding { target: self; property: "itemSelected"; value: model.selected }


                states: [

                    State {

                        name: "selected"

                        when: itemSelected

                        PropertyChanges {

                            target: self

                            opacity: 0.6

                        }

                    }

                ]

            }

        }

...
}

When I grab the model item and change the property: model.get(x).selected = true

The visual item does not change, I have checked to see that the model item property it getting set correctly: console.log("item selected: " + model.get(x).selected)

Anyone have any luck with this, is it supposed to work?

Here's the model code:


    ListModel {

        id: filteritems

        ListElement { name: "people"; selected: true }

        ListElement { name: "time"; selected: false }

    }


My setup is a little more complex, as I am writing all my components in QML directly instead of any C++ (Crazy? maybe.) So there are a few levels of components going on, but everything else is working just fine.

Thanks for looking!
Alan

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt.nokia.com/pipermail/qt-qml/attachments/20100722/610c640d/attachment.html 


More information about the Qt-qml mailing list