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. Hide an item (delegate) in a ListView

Hide an item (delegate) in a ListView

Scheduled Pinned Locked Moved Solved QML and Qt Quick
4 Posts 3 Posters 4.4k Views
  • 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.
  • MikhailGM Offline
    MikhailGM Offline
    MikhailG
    wrote on last edited by
    #1

    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
    0
    • GrecKoG Offline
      GrecKoG Offline
      GrecKo
      Qt Champions 2018
      wrote on last edited by
      #2

      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.

      MikhailGM DiracsbracketD 2 Replies Last reply
      4
      • GrecKoG GrecKo

        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.

        MikhailGM Offline
        MikhailGM Offline
        MikhailG
        wrote on last edited by
        #3

        @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
        0
        • GrecKoG GrecKo

          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.

          DiracsbracketD Offline
          DiracsbracketD Offline
          Diracsbracket
          wrote on last edited by Diracsbracket
          #4

          @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
          0

          • Login

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