PDA

View Full Version : Item Delegate editor background



LynneV
16th March 2010, 01:16
I want to set the background for the editor (not the placeholder display created by the paint method) of an Item Delegate. I'm using the Qt::BackgroundRole for the data to set the initial background in the Paint method. But, when the user places focus on the item, and the editor gets drawn, I'd like to use a different background color in the delegate's rectangle. I've tried style sheets and selected color, I've tried setting the palette for the editor, I've tried drawing the background using the selection model's QModel index, but nothing seems to work. What shall I try next? I'm using a QTrieeView, a StandardItemModel and custom data stored in a meta object.

aamer4yu
16th March 2010, 05:11
Are you using your custom editor ? if yes, editor is also a widget and you can set its background manually.
Otherwise try using stylesheet for - treeViewClass-->editorClass kind hierarchy...ie editorClass which is child of treeview...try if it works

LynneV
16th March 2010, 21:33
I tried all these methods to set the background. Including an idea from another thread that suggested using a slot that processed the selection model's change of current index. None of these worked very well.

What is working so far is to reimplement the editorEvent and use setData to change the background color role for the model index on gain focus and reset on lose focus (the reset isnt' working yet, but I'll figure it out soon).

I have a question that I wonder if you can answer... my item delegate is a frame with several child widgets. One of the things I tried was to change the color of the frame panel. The frame's geometry is to cover the whole viewport by default (it seems, anyway since that's what the outline looks like when the editor is drawn). If I change the geometry for the frame in UpdateGeometry, none of the child widgets gets drawn as an active widget - they stay just as a painted representation. Can you explain why that would happen?