PDA

View Full Version : how to change the palette while painting in QStyledItemDelegate



kgimpelson
24th February 2011, 22:52
I am using QStyledItemDelgate to provide editing widgets and paint different widget stand-ins for different data types. IE, all the items in my data model can be considered a name/value pair, of different types. Thus I want items to always appear as a checkbox for a bool, a lineedit for a string, combobox for an enum, lineedit+file browser button for a file, etc.

To do this I am using QStyle.drawComplexControl(), .drawControl(), and the passed in QPainter.drawText() as needed. Now I'd like to apply a color scheme to the painting as an indication of status for each individual item (my own custom status-- not simply an enable state, etc). I've tried passing in a QPalette via QStyle.polish() (both before and after calling drawComplexControl), but it doesn't seem to actually do anything. I don't see a way to pass a palette with the drawControl and drawComplexControl calls.

What am I missing?

tbscope
25th February 2011, 05:32
You can use the option parameter. In the option parameter you can set a palette.