Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. ListView resets delegates that have disappeared from view
Forum Updated to NodeBB v4.3 + New Features

ListView resets delegates that have disappeared from view

Scheduled Pinned Locked Moved General and Desktop
3 Posts 3 Posters 649 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.
  • J Offline
    J Offline
    joakim.g
    wrote on last edited by
    #1

    I have a list with items you can interact with and alter, but as soon as the item has been out of view it is being reset to the "base state". I include an example; clicking a tile will change its color and any tile that didn't have the highlight (i.e. all but the first in this example) will go back to black if you flick them out of view. I want them to retain their altered state. Am I doing something wrong or are ListView's not supposed to be used this way?

    @
    import QtQuick 1.1

    Rectangle {
    width: 360
    height: 360

    ListModel {
        id: model
    
        ListElement {
            name: "element";
        }
        ListElement {
            name: "element";
        }
        ListElement {
            name: "element";
        }
        ListElement {
            name: "element";
        }
        ListElement {
            name: "element";
        }
    }
    
    Component {
        id: delegate
    
        Item {
            id: delegateItem
    
            width: 40
            height: 40
    
            Rectangle {
                id: tile
    
                anchors.fill: parent;
                property int myClick: 0;
                property string myColor: "black";
                color: myColor;
    
                MouseArea {
                    anchors.fill: parent
    
                    onClicked: {
                        if (parent.myClick == 0) {
                            parent.myColor = "red";
                            parent.myClick = 1;
                        }
                        else {
                            parent.myColor = "black";
                            parent.myClick = 0;
                        }
                    }
                }
            }
        }
    }
    
    ListView {
        id: listView
        anchors.fill: parent;
        anchors.margins: 5
        model: model
        delegate: delegate
        spacing: 1
        clip: true
    }
    

    }
    @

    1 Reply Last reply
    0
    • p3c0P Offline
      p3c0P Offline
      p3c0
      Moderators
      wrote on last edited by
      #2

      Hi,

      Welcome to Qt DevNet.
      Please have a look at "this":http://qt-project.org/forums/viewthread/3016 post.

      157

      1 Reply Last reply
      0
      • A Offline
        A Offline
        andre
        wrote on last edited by
        #3

        It's a feature, not a bug.
        Please don't save state in delegates. Instead, save state in the model itself

        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