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.

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

Log in to reply

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