PDA

View Full Version : Qtableview Vertical header order



Darthspawn
24th March 2010, 09:10
In the image is possible see that the vertical header has a wrong order, this is due to the sort command, that order the rows . How can i have a vertical header ordered correctly? thanks

bmhautz
24th March 2010, 14:58
The vertical header is not being sorted, the data in your model is (and by the looks of it, it's possibly sorting on the Diff Tick column). The vertical header is probably being supplied by your headerData method or possibly by just having the vertical header visible. The only work around I can think of if you really want to go back to the vertical header being "sorted" is to add a column that mirrors the vertical header and sort on that column. Otherwise, you may have to instantiate some painful workarounds to get it the way you want.

ChrisW67
25th March 2010, 23:30
You could try creating a QHeaderView that ignores the model's header data and uses the visual section number for the label.

Darthspawn
26th March 2010, 12:56
Could you explain me how? in my table data are deleted and appended automatically, and every second is done a manual sort of the rows. I'm trying to write an headerData() that return the correct number, but it doesn't work

bmhautz
26th March 2010, 15:10
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.