[Qt-interest] Problem with QSortFilterProxyModel
bharath.narayan at nokia.com
bharath.narayan at nokia.com
Wed Oct 7 16:21:31 CEST 2009
Hi,
> 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.
Yes, I have a view and a delegate which can handle a QStringList.
> 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);
I guess I will have to implement QSortFilterProxyModel::filterAcceptsRow where I check for the role currently enabled.
In which case, I can't use the `filterRole' property from QSortFilterProxyModel. I will have to define my own property which
can hold multiple roles (Unlike filterRole, which can't handle bits). Am I correct in saying this?
> > 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.
Well in this case I think there's a bug here. The proxy model isn't updating itself when I add a new row to my source model.
i.e., the filter that I have applied, doesn't reflect the newly added it.
For example, if I am filtering based on text 'te' and there's a row which has text 'other'. Now programatically/through a menu option
I add another item which has text 'other' into the source model (i.e., a new QModelIndex). The view doesn't update to show the newly added item,
which means that the proxy model doesn't know about the source model's new item. Hence I added this.
Note that I have also set the dynamicSortFilter property to true. Inspite of this, it didn't work.
I am trying this on 4.6 tp. Am going to try this on 4.5.2 as well.
Thanks,
/Bharath
________________________________________
From: qt-interest-bounces at trolltech.com [qt-interest-bounces at trolltech.com] On Behalf Of ext Noah [noah at pcc.com]
Sent: Wednesday, October 07, 2009 7:34 PM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Problem with QSortFilterProxyModel
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
_______________________________________________
Qt-interest mailing list
Qt-interest at trolltech.com
http://lists.trolltech.com/mailman/listinfo/qt-interest
More information about the Qt-interest-old
mailing list