PDA

View Full Version : Issue with ProxyModel with tableview and VerticalHeader



alizadeh91
15th April 2013, 06:40
Hi,
Suppose using ProxyModel/Model/View.In tableView whenever the filtering occurs the numbering column(vertical Header) of tableview will filter too.
I want to have sequence of proxymodel rows in numberingColumn(vertical header) instead of sourceModel when filtering occurs. see this:
8941

I've shown with red rectangle :)
How can i do that?

Santosh Reddy
15th April 2013, 07:03
Re-Implement QAbstractItemModel::headerData() in the proxy model, and make use of signal QAbstractItemModel::headerDataChanged(), when ever filtering / sorting is applied.

alizadeh91
16th April 2013, 08:51
Thanks Reddy for reply,
What's the deal with headerData() ? I've thought that it must be setHeaderData??!!!
Anyway, how can i do that in headerData method?

Santosh Reddy
16th April 2013, 10:48
A trivial implementation will look like


class SortFilterProxyModel : public QSortFilterProxyModel
{
Q_OBJECT
public:
explicit SortFilterProxyModel(QObject * parent = 0)
: QSortFilterProxyModel(parent)
{
;
}

QVariant headerData(int section, Qt::Orientation orientation, int role = Qt::DisplayRole) const
{
if((orientation == Qt::Vertical) and
(role == Qt::DisplayRole) )
return section + 1;

return sourceModel()->headerData(section, orientation, role); //<<<<<< TODO: Make sure sourceModel() is valid
}
};

alizadeh91
16th April 2013, 12:02
Thanks, but i've already tired that! I think the default implementation of Qt is set to return section!

Santosh Reddy
16th April 2013, 13:11
Thanks, but i've already tired that!
Does that mean your problem is solved?


I think the default implementation of Qt is set to return section!
No, the default implementation of QSortFilterProxyModel::headerData() will return the section number from the source model. If you need to have continuous numbers even after applying filters, then you need to re-implement it.

alizadeh91
16th April 2013, 13:38
Thanks :) It works :)