Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

QML ListView filter items

I have a ListView table. I want to add some filter buttons to hide/show items of this table based on item type. The easiest way is set visible property of the item delegate. However, hidden items are still counted in listView.contentHeight, or listView.visibleArea.heightRatio. As a result, these values change when scrolling and affect the height and position of the scrollbar, it collapses, expands, jumps in no order.

Other issue is that in the listView, if an item is selected, there is no way to know its index, for instance it looks like it is in the second place in the table but actually its index is higher because of the invisible items. It could be nice if the invisible items are not counted at all.

Please help how to solve this issue. Thank you all.

ListView{
  id: listView
  delegate: itemdelegate
}

Component{
  id: itemdelegate
  Item{
    visible: model.type === filteredType ? true: false
  }
}
like image 565
Maluvel Avatar asked Sep 22 '14 16:09

Maluvel


1 Answers

Append items to your display model dynamically, f.e.

filterButton.onClicked:{
    for(var i = 0; i < myListModel.count;i++)
    {
        if(myListModel.get(i).desiredProperty == "desiredValue")
            myDisplayModel.append("prop1":"val1");
    }
}
like image 105
Nadarian Avatar answered Oct 05 '22 02:10

Nadarian