PDA

View Full Version : Choosing between QListWIdget / QListView with QItemDelegate



mahadevans87
14th May 2011, 17:59
Hi,

Let's say I need to display a list of items. Each item contains a QPushButton an image and some text. WHen a user clicks on the button something should happen ( ie I need to get the signal ). What is the right way to implement this in Qt?

After some reading, I understand that if I use a QListWidget and QListWidgetItem, this can be achieved. I can subclass each QListWidgetItem according to my needs and set them in the list widget.

However, I also read that a more appropriate approach ( the MOdel View approach ) is to use a QlistView coupled with a QItemDelegate. But if I'm using QItemDelegate, it seems that I can only paint the widgets. How can I get the push button event?

Sorry for this huge post. I'm kind of confused about the whole concept of when to use a QListWidget / QListView.

franz
15th May 2011, 10:11
Don't use the list widget. Model/View/Delegate helps you separate GUI from business logic. The QListWidget doesn't do that. In very simple cases you could use consider using the list widget, but as soon as you want complex stuff, use the MVD approach.