Hello !

I am using a subclassed QAbstractItemView and my model is a subclass of a QAbstractItemModel.

In my model's 'data' function I want to return a QBrush variant for the role, Qt.BackgroundRole. However I want to return an alternating row color depending on how the index is positioned in the view.

"So why don't you use QAbstractItemView.setAlternatingRowColors ?" You might ask.

Well .. the problem is two fold: Problem one is that there is only one selection color in a QAbstractItemView so you have D.I.Y. if you want to alternately color selected rows yourself. Problem two is that if you are doing some complex delegate drawing, you might want to know what brush the background is painted with.

So my question is this ... What is the best way to find out, from within the model, if you are painting an even or odd row ? Right now I'm caching this information by keeping a parallel data structure to the model, finding out what is not visible due to it being collapsed or filtered etc and then calculating odd and even that way. But this is a pain and it breaks when you start using view sorting.

Can Qt help me .... can I hijack what ever the internal mechanism is that makes setAlternatingRowColors work somehow ?

Thanks for any ideas.

barnaby.