Centering images in a QListView
The QListView is vertical list of thumbnails images. I have set the view mode to icon mode and am returning the thumbnail as the DecorationRole data. The only problem problem is all the images are left justified. It turns out the QListView is bigger then even the horizontal images, so in general there is dead space on the right.
How do you go about centering images? I am starting to think that I will have to implement my own QListView from QAbstractItemView, is that correct?
If that is the case, are there any tutorials on doing something like that such that the control will show up in Qt Designer?
Sam
Re: Centering images in a QListView
1.- try to use a custom delegate to center the image in the item
Re: Centering images in a QListView
Well, I have looked at a number of examples of custom delegates, but they all seem to be designed for editing, not just display. For some reason I am not able to make the connection on how to do what I am trying to achieve. Have you seen any good examples out there that I might have missed?
Re: Centering images in a QListView
Delegate is capable of doing that, and good thing about delegates is that Your model is intact so You can still use others views with the same model without any changes in code.
In model place your Images in UserRole (or any other role, depends what You will do in the delegate), then add custom delegate to the view.
Subclass, for example QStyledItemDelegate, and override paint() and paint You "stuff" centered. Simply calculate column and row width/height and /2 to offset image imageWIdth-Height/2.
Good example is here: http://doc.trolltech.com/4.3/itemvie...rdelegate.html