Hi there,

this post is about Qt 4.3.3.

I inherited a QSortFilterProxyModel and reimplemeted both filterAcceptsColumn() and lessThan(). setSortingEnabled(true) is set for my table view.

Things work fine to the point when I remove a column in filterAcceptsColumn(). Say, I have 5 columns in my model and in filterAcceptsColumn() I write:

Qt Code:
  1. bool MaterialDBSortModel::filterAcceptsColumn(int source_column, const QModelIndex & source_parent ) const {
  2. if (source_column == 2)
  3. return false;
  4. return true;
  5. }
To copy to clipboard, switch view to plain text mode 

to remove the third column. Now my table shows only 4 columns and here is the problem. When I click on column number 3 (corresponding to column 4 in my source model), it sorts the table based on the content of column #3 in the source model (my lessThan() function gets the data for the source model).

That is, if I use the following code:

Qt Code:
  1. bool MaterialDBSortModel::lessThan(const QModelIndex & left, const QModelIndex & right) const {
  2. QVariant leftData = sourceModel()->data(left);
  3. QVariant rightData = sourceModel()->data(right);
  4.  
  5. qDebug() << left.column(); // prints 2 when I clicked on the third column
  6. // but since I filtered the third column (index 2), I expected a print out of 3 !?!
  7.  
  8. // ... snip ... do comparison
  9. // ... snip
  10. }
To copy to clipboard, switch view to plain text mode 

just as in the example. So, I'm wondering whether lessThan() gets source ModelIndices or proxy ModelIndices. Since when I click on column 3 the model index left has the column 3, so my guess is that I get proxyIndex. But using QSortFilterProxy::data() or mapToSource() with the either parameter 'left' or 'right' always results in a crash.

What is the correct way to get the correct column data or the correct source model indices?

Thanks,
Andreas