It's a bug. Reported for 4.4.0 rc1 (and previous versions of Qt), here's the link to the tracker:
TaskTracker entry 219948
Workaround: Manually remember the number of filtered columns.
Most efficient way to do this:
Whenever a filter property of your QSortFilterProxyModel model changes, update a vector of type:
filteredColumnCount[proxy_column]
filteredColumnCount[proxy_column]
To copy to clipboard, switch view to plain text mode
Example: you have 5 columns, column with index 2 is filtered out, the vector has the content:
filteredColumnCount[0] = 0
filteredColumnCount[1] = 0
filteredColumnCount[2] = 1
filteredColumnCount[3] = 1
filteredColumnCount[0] = 0
filteredColumnCount[1] = 0
filteredColumnCount[2] = 1
filteredColumnCount[3] = 1
To copy to clipboard, switch view to plain text mode
and the sort code needs to manually shift the sort column:
// get the column to filter
int col = left.column();
// shift column to match source model column
col += filteredColumnCount[col];
return mydata(left.row(), col) < mydata(right.row(), col);
}
bool DemoSortFilterProxyModel::lessThan(const QModelIndex & left, const QModelIndex & right) const {
// get the column to filter
int col = left.column();
// shift column to match source model column
col += filteredColumnCount[col];
return mydata(left.row(), col) < mydata(right.row(), col);
}
To copy to clipboard, switch view to plain text mode
Bookmarks