Representación de una lista de selección personalizada en Qt

I'm a really confused by the different options of drawing in QT. To make it clear, I'm not asking for code. Just I'd be so thankful if someone can shed a light on the best way to implement that. I don't think it's very complicated!

Here is the result that i'm looking for!

enter image description here

The main idea is to have a textinput at the top and a list of suggestion above with matched results.

At the moment, I use a QTreeWidget, and add rows with a QTreeWidgetItem con un QStringList. Obviously it doesn't look like the screenshot :) Should i use a QItemDelegate to handle the drawing? I did some research, but it looks a bit painfull to draw with a QPainter. I thought it would be easier to implement a custom widget and replicate it somehow with maybe a QListView? QListWidget?


preguntado el 28 de agosto de 12 a las 12:08

1 Respuestas

You could indeed try to use a QListView to draw your combo, it might be a tad simpler to handle than a QTreeWidget.

Unfortunately, I'm afraid you will have to subclass a QItemDelegate (or some other kind of delegate) to handle a custom display of your data (eg, mixing an icon, a few strings and a date field...).

For the data itself, you may want to consider using a QStandardItemModel. Because you only want to display some data, overwriting the data method should be enough (along the rowCount y columCount methods, of course).

Respondido 28 ago 12, 19:08

thanks for your help! i've been able to play with setItemWidget and add some QLabel wrapped in a QWidget. I know it's not as efficient as a QPainter. Actually, I don't know how to "bind" the data on each row. I did some research on the QListView or QTreeView as you advised, the model approch is very clean but it's a lot of work just for a suggestion list imo... :/ - ablm

I just edited my answer with more pointers. Let me know what else you need. - Pedro G.M.

ah gosh! I didnt think to override it. I stared at this method, saw there is a QVariant somewhere.... and I didnt know how to put a pointer in that strange thing. Thanks, I'll consider it :p - ablm

A note to anyone who reads this answer: From assistant: Note that QStyledItemDelegate has taken over the job of drawing Qt's item views. We recommend the use of QStyledItemDelegate when creating new delegates. - Shravan

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.