[Qt-qml] Disable an item in QAbstractListModel so it doesn't show up in a ListView
Kishore
kitts.mailinglists at gmail.com
Fri Jun 24 07:56:07 CEST 2011
On Wednesday 22 Jun 2011 10:02:29 AM Matt Barclay wrote:
> Hello,
>
> I have a C++ model derived from QAbstractListModel. I want to disable
> certain elements of the model so they don't get a delegate in the ListView.
> i.e. I want them hidden from the listview. These elements can also be
> enabled under certain conditions. Think if it like an inventory system
> where the item is not displayed with quantity equals 0, but as soon as
> quanity > 0 the item reappears in the ListView.
>
> I tried using overriding QAbstractListModel::flags(index) and
> returning *QAbstractListModel::flags(index)
> & ~Qt::ItemIsEnabled;* But that isn't the same thing as removing the item
> from the view.
>
> Is this possible? I really want to avoid removing the item from the model,
> since visibility is a property of the item.
This doesn't sound right. If item exists in the model it exists in the view
even it is disabled. Look at it this way, in a table model, what should the
view show if one cell is disabled, but the next cell in the same row is
enabled!
Anyway, to achieve what you want and since you do not want to remove the item
from the model, put a proxy model in between your model and the view which
filters out the ones that you do not want to show.
--
Cheers!
Kishore
More information about the Qt-qml
mailing list