Results 1 to 3 of 3

Thread: QListView item alignment

  1. #1
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default QListView item alignment

    I'm sure this has been asked and answered a million times before but all I can find is useful "it can be done" answers, without actually saying how!

    I have a QListView with a subclassed QAbstractListModel model. The items are arranged vertically as pixmaps with a bunch of text below. The problem is that if the text is longer than the width of pixmap, them the item will be pushed to the right and the alignment of the whole list will be all over the place.

    I can set Qt::TextAlignmentRole for the text, but I can't find a way to do the same for the pixmap (icon).

    I've set setViewMode(QListView::IconMode) (and tried various combinations of the other settings).

    Also, is there an easy way of formatting the item text? Reimplementing the paint method seems overkill for something that seems to be straightforward (even if I could find some decent examples of this!)

    Thanks for your help.

  2. #2
    Join Date
    Oct 2008
    Location
    Beijing China
    Posts
    77
    Thanks
    21
    Thanked 3 Times in 3 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: QListView item alignment

    did you subclass QAbstractItemDelegate/QItemDelegate/QStyledItemDelegate or use the default delegate? and i wonder whether an item is an icon or a text or a combination of an icon and a text? if the latter guess is right, i'm afraid the only way is to implement QAbstractItemDelegate : : paint().

    ItemDelegate is responsible for the displaying mode of items, isn't it?
    Last edited by nifei; 11th November 2008 at 03:10.

  3. #3
    Join Date
    Oct 2008
    Posts
    16
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: QListView item alignment

    Thanks for the reply!
    No I didn't subclass the delegate as I was hoping that the problem could be resolved with settings.
    The item is an icon and text, with a pixmap as the icon and I would like all items lined up vertically with text below the icons.

    I could try the paint method - does anyone have a clear example of this?

    The delegate (in an MVC world, where controller is delegete) is responsible for presenting the data in the model to the view - and sometimes vica versa when editing views. That's how I see it at least.

Similar Threads

  1. How to Modify QListView item height?
    By blackfox in forum Qt Programming
    Replies: 7
    Last Post: 16th May 2012, 11:38
  2. how to move item up and down in QListView
    By zhanglr in forum Qt Programming
    Replies: 3
    Last Post: 1st August 2008, 14:39
  3. Item Delegate Painting
    By stevey in forum Qt Programming
    Replies: 3
    Last Post: 9th May 2008, 07:37
  4. QListView word wrap
    By serega in forum Qt Programming
    Replies: 17
    Last Post: 30th August 2007, 03:13
  5. moving Qlistview items
    By :db:sStrong in forum Qt Programming
    Replies: 0
    Last Post: 21st February 2006, 12:25

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.