Always display the visual index number of a QHeaderView after sorting
-
Hi,
AFAIK, you'll have to implement that yourself.
What kind of model are you using ?
-
@SGaist
Thanks for you reply.
I'm using aQAbstractTableModelso I'm already implementing theheaderData(int, Qt::Orientation, int)method and return header values for theQt::Horizontalorientation. I don't know though if this is the right place to make this work, e.g for theQt::Verticalorientation. The data structure of the model is aQMap<int,QSqlRecord*>so the entries are automatically sorted in ascending order. Then I pass this model to aQSortFilterProxyModeland sort in descending order before I display the entries in aQTableView. -
You might want to reimplement QSortFilterProxyModel::headerData to just return something like "visualIndex()" or "row()", without actually querying the source model. I am not sure if one could consider that a clean solution, but I think it is at least a very simple one.
-
You might want to reimplement QSortFilterProxyModel::headerData to just return something like "visualIndex()" or "row()", without actually querying the source model. I am not sure if one could consider that a clean solution, but I think it is at least a very simple one.
@thEClaw
Well, since you were worried about how clean your solution was, I thought I should come up with a nastier hack: -): I'm storing the ints in my map as negative numbers and then I retrieve the "real" numbers in the model'sdata()method like this:... if (item.column() == 2) { int fake = recordsMap.keys().at(item.row()); return abs(fake); } ...At least everything works and displays fine now.
I fiddled a lot with
visualIndex()andlogicalIndex()but couldn't find a way to make this work, so I'm keeping this for the time being. Thanks anyway for your suggestion!