[Qt-interest] Problem with QSortFilterProxyModel

Noah noah at pcc.com
Wed Oct 7 16:04:20 CEST 2009


Hi Bharath,

There are several things wrong here -

>     QStringList list;
>     list << "one" << "two";
>     sourceModel->setData(mdlIndex, list, Qt::DisplayRole);
>     sourceModel->setData(mdlIndex, list, Qt::DecorationRole);
I assume what you mean is

sourceModel->setData(mdlIndex, "one", Qt::DisplayRole);
sourceModel->setData(mdlIndex, "two", Qt::DecorationRole);

There's not actually anything wrong with setting a model's data as a 
QStringList, but if you want it to be visible in a view you'll have to 
write your own delegate.


>     *// proxyModel->setFilterRole(Qt::DisplayRole | Qt::DecorationRole);*
ItemDataRoles can't be combined. If you want to filter by more than one 
role you'll have to write your own proxy model subclass.

proxyModel->setFilterRole(Qt::DecorationRole);

>  
>     connect(sourceModel, SIGNAL(dataChanged(QModelIndex,QModelIndex)),
>             this, SLOT(updateProxyModel(QModelIndex,QModelIndex)));
This should be unnecessary - it's the proxymodel's job to keep itself 
updated when its source model changes.

>  
> Also, I have  certain data which I will set for  a certain role (say 
> Qt::UserRole + 1000) and I would like to filter the model based on this 
> role. Is this possible?
Yes: proxyModel->setFilterRole(Qt::UserRole + 1000);

Good luck,
  Noah



More information about the Qt-interest-old mailing list