PDA

View Full Version : QListWidget image layout



^NyAw^
26th February 2013, 10:30
Hi,

I want to show images on a QListWidget with a text at the bottom of the image. The images can be of different sizes.
I want the items to have the same size like Windows or Dolphin KDE file manager do.
I've been testing the properties "iconSize","uniformItemSizes" from QListView and "sizeHint" from QListWidgetItem with no success.
The items must be 200x200 scaling the image(icon).

Here is a picture of what I'm getting and what Dolphin does(what I need)
87708771

Thanks,

lanz
26th February 2013, 11:10
You can try using QPixmap or QImage(depending on what you use) scaled() method on the images before you add them to items.

^NyAw^
26th February 2013, 11:48
Hi,

The QListWidgetItem scales the pixmap automatically so the result is the same.

Thanks

^NyAw^
26th February 2013, 16:19
Hi,

Finally I get it setting the "iconSize" of the view to 100x100 and reescaling the image(keeping the aspect ratio).

Now the problem is that the view only shows 2 item columns although there is space enough.
Changing the "iconSize" to 200x200 and reescaling the images I only get one column.

A second problem is that I want the icon to be drawn at the center of the item. There is "textAlignment" property but no way of align the icon. Myabe the item must calculate the proper size?
8772

Thanks,

^NyAw^
26th February 2013, 18:30
Hi,

Finally It works:

If I add the items after the ui is loaded and so the QListVidget changes its size, the items are added in multiple columns. So I need to add the items not in the constructor nor after the ui is showed.

The other thing is to get the text at the bottom of the item. Setting the items "sizeHit" to the QListWidget "iconSize" plus a vertical Margin works.

Also I changed the spacing and the background of the items to not confuse between items.

Thanks,

wysota
1st March 2013, 00:51
Did you set the property in the list widget that tells it to relayout its content when its own size changes?

^NyAw^
1st March 2013, 08:38
Hi Wysota,

I didn't notice of that property. I will try it.

Thanks,