Re: Paint in a QtableView
Quote:
can't use the default alternating color
And why not? Are the colors wrong for your needs? Then change them by changing the palette for your QTableView instance. The painting code in the table widget should be doing something very similar to what you are trying.
Re: Paint in a QtableView
Alternating colors only paints the filled rows and not the entire table, in the treeview there is a option that will paint entire view but that option is not available in the tableview
Re: Paint in a QtableView
The easiest way to solve this might be to place a proxy model between your original model and the table view. The proxy will be dedicated to the view, so it can keep track of the number of filled vs. unfilled rows visible on the screen. You'll probably need to give it a pointer to the view so it can ask for geometry information; you might also connect it to scrollbar signals in the table view so it can recompute the number of "virtual rows" (model rows + empty visible rows).
In this proxy, you should re-implement rowCount() to return the count of "virtual rows". You will also need to re-implement the data() method. For each row index < source model row count, you simply call the source model's data() method. For any row index >=source model row count, you need to return an empty QVariant for the DisplayRole (to show an empty cell), and a QBrush with either the QPalette::Base or QPalette::AlternatingBase color for the BackgroundRole depending on whether the virtual row index is odd or even.
If recomputing the the virtual row count is too much hassle, you could simply say that the number of virtual rows is equal to the number of model rows plus one screen full of empty rows, and set the view's scrollbar limits appropriately. That way, unless the view is resized you can always be assured that the user can never scroll below the size of a screen full of empty rows.