PDA

View Full Version : Rendering items on QListView



rcintra
10th May 2007, 22:29
Hi,

I am starting to develop with Qt so I am sorry if my doubt is too obvious.

I am developing an UI on which there is a list that display "complex" items. I said "complex" because each item has an uncommon design and a lot of information and pictures. I have read about QListView and found I can only easily use Strings item on it. After research a little more I found out that using a QItemDelegate I would have more control on what I will render for each item using paint method.

However I would like to create a composite Widget (with layout, picture and labels) and render it as an item using ItemDelegate::paint (or another method you suggest me).

Any help is appreciated!

Thanks in advance.

Rafael

marcel
10th May 2007, 22:39
You cannot paint a widget in QAbstractItemDelegate: paint().
As far as I can see, you have two solutions:

1. Do all the painting in QAbstractItemDelegate: paint().

2. Create your widget, with everything you want in it, and then don't actually use this widget but use QPixmap::grabWidget to get a pixmap of this widget and draw this pixmap in QAbstractItemDelegate: paint(). This way would be simplwer to handle the look of the item ( you said you wanted layouts, labesl, etc )

Regards

rcintra
10th May 2007, 22:57
I was actually expecting some solution a little more elegant ! :)

I will first try solution #1 since it seems to be faster. If it turns out to be too complex I will go with #2.

Thanks a lot, Marcel.

marcel
10th May 2007, 23:06
I was actually expecting some solution a little more elegant ! :)


It can't get more elegant than this, trust me!
If you read the docs well before you start you will end-up with a pretty elegant piece of code... Because painting with QPainter is something easy and extremely used in Qt.

Regards

wysota
10th May 2007, 23:06
If an item has lots of information, maybe it's better to do it without the model-view architecture? How about using a scrollarea and a layout? The model approach is basicaly intended (but not limited to) simple (mostly non-widget) items.

rcintra
10th May 2007, 23:19
I am implementing a bank account list that each item displays the bank logo and some information about the account (number, balance, etc). I need to strictly follow a UI specification made by the project designer. I decided to use QListView because I need to be able to select an item on the list. Do you guys think that I could use a scrollarea and put the items on it as widgets dynamically? (this way I think I would have to handle the select feature by myself)

Thanks for the help again!

wysota
10th May 2007, 23:22
Do you guys think that I could use a scrollarea and put the items on it as widgets dynamically?
I do. At least I'd do it this way if I had a complex widget.


(this way I think I would have to handle the select feature by myself)
I don't think adding a checkbox into the layout is that much of a problem ;)