Results 1 to 11 of 11

Thread: Icons in a QListWidget

  1. #1
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Icons in a QListWidget

    Hello,
    Is anybody able to help me with a QListWidget? I want to create a button bar like in KDEs Kontact (but it would be very great if this can be done with Qt Designer)
    But if I want to have an longer text under the icon, the text is simply cut off like in the following screenshot:



    Is there a way that the text doesn't get cut off and I don't have to change the icon size? The function adjustSize didn't make any difference.

    I attached the source *.ui file

    Thanks,
    LuHe
    Attached Files Attached Files
    Last edited by LuHe; 25th December 2008 at 22:26. Reason: spelling error

  2. #2
    Join Date
    Dec 2008
    Posts
    16
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Icons in a QListWidget

    Add more width to it maybe? And/org use setWordWrap / setWrapping on the QListWidget.
    To get a list of "icons" with text in a line, you could also use buttons with icons, and invisible borders set in a layout.

  3. #3
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Quote Originally Posted by riklaunim View Post
    Add more width to it maybe? And/org use setWordWrap / setWrapping on the QListWidget.
    To get a list of "icons" with text in a line, you could also use buttons with icons, and invisible borders set in a layout.
    My initial problem was that I didn't want to give a fix width. It should just take as many as it needed. But even though I called adjustSize and/or set the size policy of the listWidget to preferred and the and the stackedWidget to expanding it took half of the size of the whole window.

    Thanks for the tip with the buttons, I'll try it and post the result later

  4. #4
    Join Date
    Jul 2008
    Posts
    139
    Thanks
    9
    Thanked 18 Times in 15 Posts
    Qt products
    Qt/Embedded
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Hi,
    I recently had a similar issue with this. Try tweaking the gridsize http://doc.trolltech.com/4.3/qlistvi...#gridSize-prop. It also looks like the text width is fixed to the longest item. There is another option http://doc.trolltech.com/4.3/qlistvi...ItemSizes-prop, turn that off if it is set. Also, play with the spacing attribute it may help.

  5. #5
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Quote Originally Posted by riklaunim
    To get a list of "icons" with text in a line, you could also use buttons with icons, and invisible borders set in a layout.
    There are some disadvantage for me:
    • I can't connect the ListWidget's rawChanged(int) with my stackWidget's setCurrentIndex(int)
    • I don't see any possibility to have the text under the icon


    Quote Originally Posted by QbelcorT View Post
    Hi,
    I recently had a similar issue with this. Try tweaking the gridsize http://doc.trolltech.com/4.3/qlistvi...#gridSize-prop.
    I've tried this. I changed the width of maximumSize and gridSize to 100, but it didn't change anything.
    Quote Originally Posted by QbelcorT View Post
    It also looks like the text width is fixed to the longest item. There is another option http://doc.trolltech.com/4.3/qlistvi...ItemSizes-prop, turn that off if it is set.
    This also didn't change anything. But it would be great if all icons have the same size.
    EDIT: Oh, it did work. The window in the designer wasn't updated, but afterwards I noticed the change in the preview. But uniform sizes would be really cool..
    Quote Originally Posted by QbelcorT View Post
    Also, play with the spacing attribute it may help.
    I found this in the Qt documentation: When a grid layout is in force the spacing property is ignored.

    A big thanks for all of your suggestions
    Last edited by LuHe; 26th December 2008 at 13:28. Reason: updated contents

  6. #6
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Is there a way to ensure that the whole text under an QListWidgetItem is displayed when I enable uniformItemSizes ?

    EDIT: Nevermind, i just found the solution:
    I studied the source code from Kontact and a few moments later I extended me source code with this: (unfortunately I've coded my application in Python, but it shouldn't be hard to covert this to C++):

    Qt Code:
    1. from PyQt4.QtCore import *
    2. from PyQt4.QtGui import *
    3.  
    4. import ui_mainwindow
    5.  
    6. class MainWindow(QMainWindow, ui_mainwindow.Ui_MainWindow):
    7. def __init__(self, parent):
    8. super(MainWindow, self).__init__(parent)
    9. self.setupUi(self)
    10.  
    11. maxSize = QSize()
    12. for i in range(self.listWidget.count()):
    13. itemSize = QStyledItemDelegate().sizeHint( self.listWidget.viewOptions(), self.listWidget.indexFromItem(self.listWidget.item(i)) )
    14.  
    15. if itemSize.width() > maxSize.width():
    16. maxSize.setWidth(itemSize.width())
    17. if itemSize.height() > maxSize.height():
    18. maxSize.setHeight(itemSize.height())
    19.  
    20. maxSize.setWidth(maxSize.width() + 5) # Just some spacing
    21.  
    22. for i in range(self.listWidget.count()):
    23. self.listWidget.item(i).setSizeHint(maxSize)
    24.  
    25. self.listWidget.setGridSize(maxSize)
    26. self.listWidget.setMaximumWidth(maxSize.width() + self.listWidget.rect().width() - self.listWidget.contentsRect().width() )
    27. self.listWidget.setMinimumWidth(maxSize.width() + self.listWidget.rect().width() - self.listWidget.contentsRect().width() )
    28.  
    29. self.show()
    30.  
    31. app = QApplication([])
    32. w = MainWindow(None)
    33. app.exec_()
    To copy to clipboard, switch view to plain text mode 

    For everybody who wants to do a similar thing I attatched my final *.ui file and made an screenshot:
    Attached Files Attached Files
    Last edited by LuHe; 27th December 2008 at 01:09.

  7. #7
    Join Date
    Mar 2006
    Location
    Argentina - CABA
    Posts
    66
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Nice solution, i was needed this... a shame Qt/Designer has not a better method to achieve this.

    Cheers.!
    Gustavo A. DÃ*az
    artistic.gdnet.com.ar

  8. #8
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Hey guys,
    I need you again...

    The above solution works fine with Linux/Oxygen theme and Windows XP, but looks ugly in Windows Vista and Windows 7 as you can see in these screenshots:

    Linux:


    Windows 7:


    Is it possible to extend the region of the background of a selected item in a QListWidget?

    I even tried it with a QStyledItemDelegate and QStyleOptionViewItemV4 (decorationSize attribute), but this didn't help.

    Does anybody know what I should try else?

    Thanks for your help,
    Lukas

  9. #9
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Hello,

    I've rewritten this small example in C++ and included the used icons in a resource file, maybe anybody could help me now..?

    Thanks,
    Lukas
    Attached Files Attached Files

  10. #10
    Join Date
    Dec 2008
    Posts
    7
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Icons in a QListWidget

    Could anybody help me with this issue?
    It's the last bug in my application that needs to be fixed, before I can
    release a new version :-(

  11. #11
    Join Date
    Aug 2008
    Posts
    18
    Thanks
    2
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Icons in a QListWidget

    There is a simple solution: Adjust the iconSize (default is 0 x 0) of your QListWidget properties in QT Designer.

    Yi

Similar Threads

  1. no icons on the another machine (after installation)
    By roxton in forum Installation and Deployment
    Replies: 2
    Last Post: 4th July 2008, 17:24
  2. QListWidget Problem
    By pmabie in forum Qt Programming
    Replies: 1
    Last Post: 7th October 2007, 06:52
  3. Default size of a QListWidget inside a QDockWidget
    By rakuco in forum Qt Programming
    Replies: 0
    Last Post: 25th July 2007, 08:01
  4. QIcon Icons are not visible
    By harakiri in forum Qt Programming
    Replies: 1
    Last Post: 6th May 2007, 19:11
  5. Replies: 13
    Last Post: 15th December 2006, 11:52

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.