Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved Hide an item (delegate) in a ListView

    QML and Qt Quick
    3
    4
    3159
    Loading More Posts
    • 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.
    • MikhailG
      MikhailG last edited by

      Hello! Is there a way to hide a particular item on some event in a ListView? So far I can do it by setting visible to false and height to zero. But If i have spacing in a listView set to 2 for example it appears that this solution is broken.
      0_1517494808552_item.gif

      1 Reply Last reply Reply Quote 0
      • GrecKo
        GrecKo Qt Champions 2018 last edited by

        Set its height to -spacing :P

        A problem with your solution is that if you scroll away and come back, the delegate will have beem reinstantiated and will be visible again.
        You shouldn't store state in your delegates since they are not persistant.
        A solution would be to have a toggle role in your model and filter your model with a QSortFilterProxyModel filtering on that role.

        MikhailG Diracsbracket 2 Replies Last reply Reply Quote 4
        • MikhailG
          MikhailG @GrecKo last edited by

          @GrecKo indeed height - spacing does the trick. Thank you. And as for issue #2 I do store the state of a delegate in a model.

          1 Reply Last reply Reply Quote 0
          • Diracsbracket
            Diracsbracket @GrecKo last edited by Diracsbracket

            @GrecKo said in Hide an item (delegate) in a ListView:

            Set its height to -spacing :P

            Thanks! That helped me too, on a similar problem where I swipe to "remove" the item from the list.

            @GrecKo said in Hide an item (delegate) in a ListView:

            A solution would be to have a toggle role in your model and filter your model with a QSortFilterProxyModel filtering on that role

            Unfortunately, in my case, my model is a XmlListModel, which is read-only :-(. And even thought I use a Proxymodel on that, I haven't found a way to add some custom editable role to it (other than, of course parsing he XML file and store the data in an editable data model instead of using XmlListModel)

            @GrecKo said in Hide an item (delegate) in a ListView:

            You shouldn't store state in your delegates since they are not persistant.

            I avoid this problem by making sure the cacheBuffer property of the ListView is set to a sufficiently large value to keep all delegates in memory, since my list is not that large.

            1 Reply Last reply Reply Quote 0
            • First post
              Last post