[Qt-interest] QSortFilterProxyModel / lazy population - hasChildren

Florian Turck mail at florianturck.de
Mon Dec 14 18:11:58 CET 2009


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?

Thanks

Florian

-- 

Florian Turck
Barnerstraße 20
22765 Hamburg

Telefon 040  228155350
Mobil   0178 2892068
Fax     040  228155359

E-Mail  mail at florianturck.de
ICQ     361002295
Skype   florian.turck
PGP-Key http://pgp.florianturck.de/pgp.asc
				
--



More information about the Qt-interest-old mailing list