Hide an item (delegate) in a ListView



  • 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



  • 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.



  • @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.



  • @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.


Log in to reply
 

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