drag-and-drop columns.
-
@JonB said in drag-and-drop columns.:
I would expect that after hiding a column the column(s) to the right would have visual indexes one less than the model indexes they show.
Unfortunately, I tested it, it does not decrease.
@JonB said in drag-and-drop columns.:
normally the visual index is the same as the model index, but once you hide a column they will differ.
No, as I said, when we hide the column, the visual index numbers still do not change (unless we move the columns). So the model index is the same as the visual index.
@Nevez
OK, I've had a search. This was covered in the https://uvesway.wordpress.com/2013/01/08/qheaderview-sections-visualindex-vs-logicalindex/ reference @mrjj gave you, did you read it?Visual indexes tell us the current position that a given section occupies in the header.
However there is a detail one has to be aware of: hiding/showing a given section (calling QHeaderView.hideSection method) does NOT change its visual index as one could expect.
So it's perfectly clear: visual indexes are for when you re-order the view columns, but if you only hide a column it (and subsequent columns) still retain their index into the header columns.
As I say, I haven't used visual indexes/hiding of columns. But if there is not some better way you would need to write code to map from on-screen-visible columns to underlying column numbers by taking into account which column(s) are hidden where. Which is just some code to write.