Results 1 to 7 of 7

Thread: QListView of images

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

    Question QListView of images

    I need to display a list of thumbnail images in a QListView. My data source is a database and I recalled seeing the Drill Down Example in the QSql example section, but that isn't using a QListView to display the images. Can anyone point me to a good example?

    Sam

  2. #2
    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: QListView of images

    Just set the list view in icon mode and add the thumbnails as DecorationRole data in your model.
    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.


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

    Default Re: QListView of images

    It cannot be that easy, programming is suppose to be hard. There was even a blog about Programming will never be “easy”

    thanks!

  4. #4
    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: QListView of images

    Quote Originally Posted by scarleton View Post
    It cannot be that easy, programming is suppose to be hard.
    "Code less, create more, deploy everywhere"

    By the way, the blog is wrong about its theses. There are declarative languages that actually do what's "dreamed of" there. Actually even Qt has such a language (QML).
    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.


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

    Default Re: QListView of images

    Ok, so the image shows up just fine. There are two tweaks I would like to make:

    1: Center the image/text: The model's data() function does return Qt::AlignHCenter | Qt::AlignVCenter for Qt::TextAlignmentRole, but that doesn't do any thing. What is the correct way to center it?

    2: Currently when you select an image, the image picks up the cast of the selection color. Is there some way to not change the image, just the text under it?

  6. #6
    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: QListView of images

    1. Subclass delegate and override Paint(). That way You can paint images the way You want.
    2. You want the selection to be only around text not around image? AFAIK use styles to do that, there was similar problem on the board recently, or subclass listview and override appropriate method.

  7. #7
    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: QListView of images

    Quote Originally Posted by Talei View Post
    1. Subclass delegate and override Paint(). That way You can paint images the way You want.
    2. You want the selection to be only around text not around image? AFAIK use styles to do that, there was similar problem on the board recently, or subclass listview and override appropriate method.
    There is no need for such drastic measures especially that reimplementing the delegate and using stylesheets at the same time is often impossible or at least redundant (if you do your own painting then you can simply tell the style not to highlight the decoration).

    Ad #1: What output do you get now? From what I remember by default the text should be centered under the icons
    Ad #2: Some styles don't highlight the image so either use one that doesn't or implement a style proxy that will set the proper option for the current style to follow. This way you will interfere as least as possible into how the drawing works and it'll be least likely that you break something else.
    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.


Similar Threads

  1. QListView
    By Yayati.Ekbote in forum Qt Programming
    Replies: 2
    Last Post: 1st March 2010, 11:41
  2. Images
    By ToddAtWSU in forum Qt Programming
    Replies: 2
    Last Post: 15th December 2009, 15:22
  3. help: about images
    By miguel_mark in forum Qt Programming
    Replies: 2
    Last Post: 8th December 2009, 07:10
  4. Replies: 4
    Last Post: 27th July 2009, 15:45
  5. QListView
    By moowy in forum Qt Programming
    Replies: 2
    Last Post: 2nd October 2006, 14:14

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.