Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. QML and Qt Quick
  4. bind to model data on other role from item delegate
Qt 6.11 is out! See what's new in the release blog

bind to model data on other role from item delegate

Scheduled Pinned Locked Moved Unsolved QML and Qt Quick
tableviewmodel
1 Posts 1 Posters 640 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alexander_Lanin
    wrote on last edited by
    #1

    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 });
    
    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved