[Qt-interest] QSortFilterProxyModel / lazy population - hasChildren
Sean Harmer
sean.harmer at maps-technology.com
Mon Dec 14 18:18:51 CET 2009
Hi,
On Monday 14 December 2009 17:11:58 Florian Turck wrote:
> Hi,
>
> I have written a custom model that is a subclass of QAbstractItemModel.
> To make lazy population of the data possible I have overwritten
> hasChildren, canFetchMore and fetchMore. Using the model with QTreeView
> works fine.
>
> Now I want to add sorting and filtering of some item. I suclassed
> QSortFilterProxyModel to use the sorting implemented in it. I have
> overwritten filterAcceptsRow to filter out some indexes. I have
> overwritten hasChildren in order to make it call the hasChildren
> implementation of the source model.
>
> I try to use the models like this:
>
> model = new MySourceModel(this);
> filterModel = new MySortFilterModel(this, true);
> filterModel->setSourceModel(model);
> filterModel->setFilterKeyColumn(0);
> treeView = new QTreeView(this);
> treeView->setModel(filterModel);
>
> Unfortunatly this fails. When setModel(...) is called the data of the
> source model has not yet been populated.
> MySortFilterModel::hasChildren() is not called before the view tries to
> access children.
>
> Reading the documentation I thought it would be enough to overwrite
> QSortFilterProxyModel::hasChildren and to make it call
> MySourceModel::hasChildren. Any ideas what I am missing?
Why do you need to override hasChildren() at all? The standard implementation
should do what you need. Or am I missing something?
Sean
More information about the Qt-interest-old
mailing list