PDA

View Full Version : Can I use a QWidget as a renderer in an ItemDelegate?



boblebel
2nd May 2009, 19:18
Hi all,

For those familiar with the ListCellRenderer concept in Swing, is there a way to do the equivalent with QT?

I have to implement a custom delegate for my listview, but the layout is a bit complicated (see the attached file to see an example of what i want to do).

In swing, as i remember it, i would create this layout in a component, and use this component as a stamp to paint each row.

I can't figure out how to do the same with QT. I'd like my delegate to have a single instance of a component. Each time paint() is called on my delegate, i would populate this component with data for the current row, then render this component to paint the row.

Is this possible? Or is there a better way that i'm missing?

Lykurg
2nd May 2009, 19:52
Hi,

what you can do is to create your own QWidget with all the other stuff inside, resize it to the available space and then use
QPixmap pixmap(widget->size());
widget->render(&pixmap);
Then you can simply set the image wherever you want, but that's not very efficient. For your design just use the normal painter function like drawPixmap, drawText etc. It isn't that difficult.

boblebel
2nd May 2009, 20:03
Thanks, i'll try the pixmap approach.