Results 1 to 4 of 4

Thread: Centering images in a QListView

  1. #1
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Question Centering images in a QListView

    The QListView is vertical list of thumbnails images. I have set the view mode to icon mode and am returning the thumbnail as the DecorationRole data. The only problem problem is all the images are left justified. It turns out the QListView is bigger then even the horizontal images, so in general there is dead space on the right.

    How do you go about centering images? I am starting to think that I will have to implement my own QListView from QAbstractItemView, is that correct?

    If that is the case, are there any tutorials on doing something like that such that the control will show up in Qt Designer?

    Sam

  2. #2
    Join Date
    Oct 2009
    Location
    Mexico
    Posts
    81
    Thanks
    6
    Thanked 10 Times in 10 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Centering images in a QListView

    1.- try to use a custom delegate to center the image in the item

  3. #3
    Join Date
    Jun 2010
    Location
    Cincinnati, Ohio, USA
    Posts
    92
    Thanks
    3
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Centering images in a QListView

    Well, I have looked at a number of examples of custom delegates, but they all seem to be designed for editing, not just display. For some reason I am not able to make the connection on how to do what I am trying to achieve. Have you seen any good examples out there that I might have missed?

  4. #4
    Join Date
    Dec 2008
    Location
    Poland
    Posts
    383
    Thanks
    52
    Thanked 42 Times in 42 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Android

    Default Re: Centering images in a QListView

    Delegate is capable of doing that, and good thing about delegates is that Your model is intact so You can still use others views with the same model without any changes in code.
    In model place your Images in UserRole (or any other role, depends what You will do in the delegate), then add custom delegate to the view.
    Subclass, for example QStyledItemDelegate, and override paint() and paint You "stuff" centered. Simply calculate column and row width/height and /2 to offset image imageWIdth-Height/2.
    Good example is here: http://doc.trolltech.com/4.3/itemvie...rdelegate.html

Similar Threads

  1. Vertical centering of a QTextEdit
    By miwarre in forum Newbie
    Replies: 4
    Last Post: 5th October 2015, 05:01
  2. QListView of images
    By scarleton in forum Newbie
    Replies: 6
    Last Post: 5th September 2010, 08:07
  3. Centering a QCheckBox in a TableView
    By scarleton in forum Qt Programming
    Replies: 2
    Last Post: 6th July 2010, 15:13
  4. Centering a window
    By dwarnold45 in forum Newbie
    Replies: 1
    Last Post: 30th March 2010, 07:43
  5. Centering An Icon In A QTableWidgetItem?
    By mclark in forum Qt Programming
    Replies: 3
    Last Post: 14th November 2007, 23:11

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.