Results 1 to 7 of 7

Thread: QListView Text Elide Like QListWidget

  1. #1
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default QListView Text Elide Like QListWidget

    Hello,

    I would like to know how the QListWidget setup in iconMode is doing to elide the text under the icon in order to do the same with a QListView.

    I have setup a QListView and a QListWidget, a QStandardItemModel is used to feed the QListView.

    Here a screen of the widgets, the top one being the QListView, the bottom one being the QListWidget :



    as you can see the QListWidget is eliding the texts nicely.

    Now here is a test using the setUniformItemSizes method of the QListView :



    Better but not really perfect.

    KS

  2. #2
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QListView Text Elide Like QListWidget

    Take a look at QListView::setGridSize()

  3. #3
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView Text Elide Like QListWidget


  4. #4
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView Text Elide Like QListWidget

    Hello,

    Thanks for the replies !

    Unfortunatly the QAbstractItemView::setTextElideMode didn't helped, I think the size of the delegate is calculated with some dependency on the text data width, changing the icon size was'nt affecting my listview the way I want.
    The problem with the QListView::setGridSize() is that it's killing spacing around the items producing something like this :



    Ayway I got something I'm satisfied with by setting a new size hint everytime the icon size change :

    Qt Code:
    1. for i in range( self._model.rowCount() ) :
    2. iblSetStandardItemItem = self._model.item( i )
    3. iblSetStandardItemItem.setSizeHint( QSize( value, value + 16 ) )
    To copy to clipboard, switch view to plain text mode 

    "16" being the margin I add to display the text.

    KS

  5. #5
    Join Date
    Feb 2008
    Posts
    491
    Thanks
    12
    Thanked 142 Times in 135 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: QListView Text Elide Like QListWidget

    Glad that you solved your problem. I don't mean to be a contrarian but by varying the width and/or height in setGridSize() can't you achieve the same result?
    Attached Images Attached Images

  6. The following user says thank you to norobro for this useful post:

    Kel Solaar (12th May 2010)

  7. #6
    Join Date
    Jun 2009
    Posts
    5
    Thanks
    1
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: QListView Text Elide Like QListWidget

    Yeah It does the trick in an even sexier way ! Dunno why I didn't thought putting a gridSize bigger than my icons width Thanks again !

  8. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: QListView Text Elide Like QListWidget

    for i in range( self._model.rowCount() ) :
    iblSetStandardItemItem = self._model.item( i )
    iblSetStandardItemItem.setSizeHint( QSize( value, value + 16 ) )
    From above it seems you are using your own model..
    Instead of iterating over all items and setting their size hint, you can return the size hint from model::data function too.

Similar Threads

  1. add custom widget items to QListView or QListWidget
    By yazwas in forum Qt Programming
    Replies: 2
    Last Post: 16th September 2010, 23:36
  2. QListWidget or QListView with QLabel(s)
    By lukass in forum Newbie
    Replies: 6
    Last Post: 11th August 2008, 10:48
  3. Replies: 6
    Last Post: 1st July 2008, 21:34
  4. QListWidget::currentRowChanged() for QListView
    By Lykurg in forum Qt Programming
    Replies: 1
    Last Post: 13th March 2007, 16:27
  5. QListWidget / QListView Bug ?
    By guilugi in forum Qt Programming
    Replies: 5
    Last Post: 16th November 2006, 12:33

Tags for this Thread

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.