PDA

View Full Version : QListView of images



scarleton
30th August 2010, 14:26
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 (http://doc.qt.nokia.com/4.6/sql-drilldown.html) 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

wysota
30th August 2010, 14:59
Just set the list view in icon mode and add the thumbnails as DecorationRole data in your model.

scarleton
30th August 2010, 15:04
It cannot be that easy, programming is suppose to be hard. There was even a blog about Programming will never be “easy” (http://mdmstudios.wordpress.com/2010/08/28/programming-will-never-be-easy/) :cool:

thanks!

wysota
30th August 2010, 15:13
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).

scarleton
4th September 2010, 04:16
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?

Talei
4th September 2010, 21:54
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.

wysota
5th September 2010, 08:07
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.