Results 1 to 7 of 7

Thread: QListWidget image layout

  1. #1
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default QListWidget image layout

    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)
    image2.jpgimage1.jpg

    Thanks,
    Òscar Llarch i Galán

  2. #2
    Join Date
    Dec 2012
    Posts
    90
    Thanks
    5
    Thanked 20 Times in 18 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget image layout

    You can try using QPixmap or QImage(depending on what you use) scaled() method on the images before you add them to items.

  3. #3
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget image layout

    Hi,

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

    Thanks
    Òscar Llarch i Galán

  4. #4
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget image layout

    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?
    image3.jpg

    Thanks,
    Òscar Llarch i Galán

  5. #5
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget image layout

    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,
    Òscar Llarch i Galán

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: QListWidget image layout

    Did you set the property in the list widget that tells it to relayout its content when its own size changes?
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Jan 2006
    Location
    Sta. Eugènia de Berga (Vic - Barcelona - Spain)
    Posts
    869
    Thanks
    70
    Thanked 59 Times in 57 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: QListWidget image layout

    Hi Wysota,

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

    Thanks,
    Òscar Llarch i Galán

Similar Threads

  1. Need Image rightside of QListwidget
    By rajeshs in forum Qt Programming
    Replies: 18
    Last Post: 12th February 2013, 21:46
  2. Replies: 2
    Last Post: 1st April 2011, 10:32
  3. Layout modification in QListWidget
    By ouekah in forum Newbie
    Replies: 2
    Last Post: 20th March 2010, 07:15
  4. Hw to add a image on QlistWidget's seletced item
    By kellen851105 in forum Qt Programming
    Replies: 1
    Last Post: 25th February 2010, 12:19
  5. How to add image in QListWidget
    By mekos in forum Qt Programming
    Replies: 8
    Last Post: 4th August 2008, 19:19

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.