PDA

View Full Version : QListView item alignment



innerhippy
10th November 2008, 14:07
I'm sure this has been asked and answered a million times before but all I can find is useful "it can be done" answers, without actually saying how!

I have a QListView with a subclassed QAbstractListModel model. The items are arranged vertically as pixmaps with a bunch of text below. The problem is that if the text is longer than the width of pixmap, them the item will be pushed to the right and the alignment of the whole list will be all over the place.

I can set Qt::TextAlignmentRole for the text, but I can't find a way to do the same for the pixmap (icon).

I've set setViewMode(QListView::IconMode) (and tried various combinations of the other settings).

Also, is there an easy way of formatting the item text? Reimplementing the paint method seems overkill for something that seems to be straightforward (even if I could find some decent examples of this!)

Thanks for your help.

nifei
11th November 2008, 02:32
did you subclass QAbstractItemDelegate/QItemDelegate/QStyledItemDelegate or use the default delegate? and i wonder whether an item is an icon or a text or a combination of an icon and a text? if the latter guess is right, i'm afraid the only way is to implement QAbstractItemDelegate : : paint().

ItemDelegate is responsible for the displaying mode of items, isn't it?

innerhippy
11th November 2008, 09:32
Thanks for the reply!
No I didn't subclass the delegate as I was hoping that the problem could be resolved with settings.
The item is an icon and text, with a pixmap as the icon and I would like all items lined up vertically with text below the icons.

I could try the paint method - does anyone have a clear example of this?

The delegate (in an MVC world, where controller is delegete) is responsible for presenting the data in the model to the view - and sometimes vica versa when editing views. That's how I see it at least.