bind to model data on other role from item delegate



  • It seems dataChanged doesnt affect qml in my case. I'm trying to bind a delegate to data from another model role (see code). Is there any workaround? Am I doing it wrong or is this a bug?
    My model is a QAbstractListModel.

        TableView
        {
            TableViewColumn
            {
                title: "X"
                role: "x"
    
                delegate: Rectangle
                {
                    // both ways do not update after initial drawing:
                    //color: model["y"] ? "red" : "transparent"
                    Component.onCompleted: color = Qt.binding(function() { return model["y"] ? "red" : "transparent" })
    
                    Text {
                        text: styleData.value
                        color: styleData.textColor
                        anchors.verticalCenter: parent.verticalCenter
                        elide: styleData.elideMode
                        leftPadding: 1
                        rightPadding: 1
                    }
                }
            }
    
            model: myModel
        }
    

    I've printed some of my dataChanged calls which obviously have no effect in this case. I added trace calls to data() so I'm sure it's not called again.

    emit dataChanged(index(0), index(11259), { (int)Roles::y });
    emit dataChanged(index(0), index(11259), { (int)Roles::y });
    emit dataChanged(index(0), index(11259), { (int)Roles::y });

Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.