Is it possible to show only certain indexes or a range of indexes in QML listviews?
I have a listmodel that has a bunch of info that I am reusing. Would it be possible to have a list showing, for example, only indices 5 to 8?
You could accomplish that by setting the delegate visibility to false on certain conditions:
Grid {
anchors.fill: parent
rows: 4
columns: 5
spacing: 5
Repeater {
model: 20
delegate: Rectangle {
width: 50
height: 50
visible: index >= 5 && index <= 8 // show only certain indices
Text {
anchors.centerIn: parent
text: index
}
}
}
}
It will have some overhead of creating hidden items in memory thou, so not optimal if you deal with very large models and showing only small portions of them.
Yes, it is possible. You need to override QSortFilterProxyModel::filterAcceptRow
method.
MyFilterModel::filterAcceptsRow ( int source_row, const QModelIndex & source_parent ) const
{
if ( source_row > 5 && source_row < 8 )
return true;
return false;
}
//...
MyFilterModel *filter = new MyFilterModel();
filter->setSourceMoldel( yourSourceModel );
view->setModel( filter );
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With