[Interest] Customize QTableView selection color

André Somers andre at familiesomers.nl
Fri Feb 5 17:48:56 CET 2016



Op 05/02/2016 om 17:39 schreef Murphy, Sean:
>> If I understand you correctly, you basicaly want the color of the row to be whatever it was before it was selected, right?
>>
>> Can't you just use a QProxyStyle and reset the selected flag from the style option before you pass on the render command to the underlying style?  Have the selection work, but not be visible. A QStyledItemDelegate doing a similar trick
>> would work as well. Just make a copy of the style option, reset the selection flag in the state variable, and pass that on to the base class.
> I'll try that. As I said in the post I made on January 29th, I was completely getting lost between who's responsibility it is to customize these things: stylesheets, QStyle, QStyledItemDelegate, the model, the view itself, etc. So this is helpful to at least get thing narrowed down.
>
Well, there are several ways to do the same thing... A brief overview.

I'd avoid style sheets. They are slow, and full of nasty little 
suprises. It is easy to get started with, but hard to maintain in the 
long run.
Styles give you more control how stuff looks. They are harder to write, 
but easier to maintain in the long run. And using a proxy style, you can 
also tweak existing styles where needed, making the entry barrier lower.
Models can also suggest some formatting for items. Use sparingly. It 
really should not be the model's task to determine the presentation.
The actual rendering of items in the view is done by delegates. 
Delegates can completely determine how items look and what is displayed, 
but usually they defer to the style for that. They can be very powerfull 
to render non-standard items, modify data before it is rendered, etc. 
The QStyledItemDelegate is the standard delegate that takes things like 
style sheets into account.

So, you have multiple angles of attack here.

André






More information about the Interest mailing list