If you really wanted the numbers for the vertical column to be correct that are set using the headerData() function, the only thing I can think of is to sort your data manually as you receive it and bypass the view sorting, and then return the correct row number as usual.

Let me put this another way: Right now what is probably happening (without being able to see your code) is that you are setting the data in the model, adding new data to the end, and setting the row number in headerData() based on the original data. In this scenario, the numbers in the vertical column should be correct since the view is just reflecting the data in your model. However, instead of showing the original data, you are now enabling sorting on the model through either a proxy or the view itself. What happens in this case is now the vertical header numbers are still attached to the data in that row, so when the rows are sorted, the vertical header numbers are now non-sequential. If you're using a proxy model in this case, then maybe you can write your own headerData function that overrides the model's headerData, but this can be a little tricky.

In my opinion, if this really matters to you, then I would manually sort your own data in the model and turn off sorting in the view. That way, your data is sorted and the vertical header numbers are sequential.