PDA

View Full Version : Custom widget in list view



fusoin23
17th November 2006, 04:22
I'm just starting to learn Qt and my c++/programming skills in general are a little rusty. A friend and I are writing a simple asset management application. I'm charged with programming the GUI.

My problem is:

I want to be able to create my own unique look for the thumbnail when I view all images. I can create my own widget and override the paintEvent() function to create what I want. But how can I use this widget in a list view (or any view for that matter).

From what I've been reading, especially on this forum, is to derive my own delegate (espcially if the content may be dynamically updated). For now, lets assume static content. I've also read using QAbstractItemView::setIndexWidget() but I cannot for the life of me figure out where to put the call and how to properly format it. Where do I get the QModelIndex from??

I'm basing my code right now off the Puzzle example from Trolltech, using the model-view architecture (which is a little confusing to me, too)

For example:

I have a mainwindow which sets up the layout and menus.
mainwindow also sets up a QListView and sets many of its options.
I have a model called AssetModel acting on my QListView. It stores the data in a QList<QPixmap>.

Right now, i can add images to my model, and they get displayed in the QListView. It works, but is not very pretty.

I also have a customWidget (right now all it does is paint a purple square), but lets say instead of adding an image to the QListView, I would like to add my customWidget instead. How do I go about this?

Also, in general, in trying to follow how the model-view code is working...Where is data() being called from? inside my QListView? I notice the ability to call data() with a userRole? To use the userRole, would I have to implement my own ListView?

I know this is a large post, but I really want to understand.

Thank you for any help or direction...

-Kevin-

p.s. I can post code if you want.

e8johan
18th November 2006, 14:09
You call data from your delegate when you paint your information.