Results 1 to 13 of 13

Thread: photo thumbnail viewer

  1. #1
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Lightbulb photo thumbnail viewer

    I'm looking to create a grid based photo album viewer similar to the image I attached below from Adobe Lightroom (see the center tool).

    The idea being that you can scale the view which would change how many thumbnails are displayed on a given row. I also want to be able to rearrange the thumbnails in the grid and even have empty cells between images.

    I was thinking that there are a few ways to go about this but I wanted to see if anyone thought one way might be better than another.

    1. Use a QGraphicsView
    • not sure how to accomplish it with a QGraphicsView especially when it comes to zooming since the QGraphicsView zoom scales the painter and doesnt give you a real flow layout. (right?) though i probably dont need to use the graphics view to scale/zoom
    • I would think this would be the most flexible, allow interesting things like grouping thumbnails and such, not sure how to do it


    2. Use a QListView and turn on QListView::IconMode.

    • create thumbnail items and place holder items to simulate a grid?
    • probably use an item delegate for finer control


    3. Write it from scratch and use the example "FlowLayout"

    Any ideas?
    Attached Images Attached Images

  2. #2
    Join Date
    Dec 2007
    Posts
    628
    Thanks
    3
    Thanked 89 Times in 87 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: photo thumbnail viewer

    I 'd suggest to go with QGraphicsView.
    When you need to scale many items, just scale the graphics View and everything inside will be scale accordingly.

  3. #3
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: photo thumbnail viewer

    Quote Originally Posted by yogeshgokul View Post
    When you need to scale many items, just scale the graphics View and everything inside will be scale accordingly.
    In that particular case scaling the whole scene makes no sense. But you can call all items with a scale value, draw them new and then rearrange the items in the view:
    • Status: scale by 20%
    • calculate the new with of the item (according also to the width of the view)
    • call all items with 20% and the new calculated width (!= width of the picture)
    • in the items draw method draw the picture and the gray border
    • then rearrange the items in the view


    voila!

  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: photo thumbnail viewer

    I'd go for QListView. Unless you want some wacky animations, there is nothing Graphics View can give you here.
    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
    Sep 2009
    Posts
    140
    Thanks
    4
    Thanked 17 Times in 17 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: photo thumbnail viewer

    If I may, I would say that QGraphicsView is not adapated to your case, except for scaling functions, since you will have a single row and propably need to move your items often.

    Why not making your own widget and use an array of QLabel, displayed on an QHBoxLayout with spacers? You can overload the resize event to scale the images, if it dos not do it automatically with the strench option and provide an empty label item.

    Good luck

    S.Cascio

  6. #6
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: photo thumbnail viewer

    Quote Originally Posted by scascio View Post
    If I may,
    Of course you can, we are open minded and everybody is free to speak!
    I would say that QGraphicsView is not adapated to your case, except for scaling functions, since you will have a single row and propably need to move your items often.
    With a QListView you can scale the items also quite easy using a custom delegate or simple use the gridsize and iconSize property. (I haven't thought of that in my first post)

    Why not making your own widget and use an array of QLabel, displayed on an QHBoxLayout with spacers? You can overload the resize event to scale the images, if it dos not do it automatically with the strench option and provide an empty label item.
    If the items change a lot (I guess it will be the case, if it is used like a folder preview) that solution has a bad performance.

    Quote Originally Posted by wysota View Post
    I'd go for QListView. Unless you want some wacky animations, there is nothing Graphics View can give you here.
    You also can make some nice and pleasing animations with Graphics View
    Ok, I was prejudiced because I have to do a similar work in some weeks and I have decided to use graphics view. This is because I want to display some "image buttons" beneath the pictures for rotating, editing etc. And if you alter the first question for this points, do you would still use a list view? Which means you have do deal with a custom delegate and with e.g pressed(const QModelIndex&) in conjunction with QCursor::pos() to determinate if a modifying button was pressed. Or would there be an other possibility?


    Thanks

  7. #7
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: photo thumbnail viewer

    Yeah, thats kind of where I'm at. The QListView seems like the most straight forward but is probably the least flexible in terms of customizing the view. I like the idea of using a QGraphicsView and in that rite I'm a bit biased too, but it's certainly a more complex implementation especially when it comes to layout.

    I have a widget already implemented using the flow layout example (http://doc.trolltech.com/layouts-flowlayout.html) in a scroll area where the thumbnails are widgets I'm painting. That works alright but the flow layout, which is really similar to the QListView, dictates the placement of the thumbnails... that is unless I put placeholder widgets/items in there to simulate a grid.

    I also have a simple QGraphicsView implementation, but with no real grid system. I posted the code for that a while back when I started thinking about this problem http://www.qtcentre.org/forum/f-qt-p...iew-15739.html

    The graphics view allows you to draw the grid on the background plane which is enticing, and you can add nice delighters like animations fairly easily. Its just managing that darn layout.

    Anyway, it seems like a pretty equally weighted decisiion, they could all certainly work. I'm sure I'll be back for more questions but hopefully I can bug my boss into letting me post the source for the widget for you guys to tear apart

  8. #8
    Join Date
    Jan 2006
    Location
    Knivsta, Sweden
    Posts
    153
    Thanks
    30
    Thanked 13 Times in 12 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11

    Default Re: photo thumbnail viewer

    that is unless I put placeholder widgets/items in there to simulate a grid.
    Have you also considered using a QGridLayout?

  9. #9
    Join Date
    Jan 2006
    Location
    Germany
    Posts
    4,380
    Thanks
    19
    Thanked 1,005 Times in 913 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows Symbian S60
    Wiki edits
    5

    Default Re: photo thumbnail viewer

    If you don't want to do the layout in a Graphics View by your own, even if it's not so complicated, QGraphicsGridLayout/QGraphicsLinearLayout could be an option for you.

  10. #10
    Join Date
    Dec 2009
    Location
    Barcelona
    Posts
    3
    Thanks
    1
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: photo thumbnail viewer

    Hello to everybody!

    I have just registered today and it is 2 months since I am trying with Qt 4.5 in-depth... but very happy with Qt!
    Sometimes I feel rather alone investigating... That's why I'm here!

    My need is very close (thumbnails viewer similar to lightroom) to chezifresh.
    I decided to implement it with qgraphicsgridlayout (thumbnail matrix 5x5), and I am progressing fine but slow..., nevertheless some issues have appeared to me:

    1) I can not display the thumbnails without any separation among them (as in lightroom).
    Qtgraphicsgridlayout performs it bay itself.
    Is there any bug? I have played with Qt functions but no good results.
    2) When moving images with my implementation of dnd, the initial thumbnail separation varies and rendering after scene.update is not clean.

    It would be nice to discuss these topics with somebody!
    Attached Images Attached Images

  11. The following user says thank you to carlossst for this useful post:

    thaihoangluu (22nd December 2011)

  12. #11
    Join Date
    Dec 2011
    Posts
    33
    Thanks
    56
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: photo thumbnail viewer

    who can share this code?
    Thanks

  13. #12
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: photo thumbnail viewer

    there are examples and demos in the qt install. why not look at those?
    If you have a problem, CUT and PASTE your code. Do not retype or simplify it. Give a COMPLETE and COMPILABLE example of your problem. Otherwise we are all guessing the problem from a fabrication where relevant details are often missing.

  14. #13
    Join Date
    Jun 2008
    Posts
    88
    Thanks
    4
    Thanked 4 Times in 3 Posts
    Qt products
    Qt3 Qt4
    Platforms
    MacOS X Unix/X11
    Wiki edits
    1

    Default Re: photo thumbnail viewer

    Here's essentially what I decided on. In general its a QListView or QListWidget (depending on if you want to write your own model, which is good if you have multiple views, ie. list view and icon view). I also use a QStyledItemDelegate to draw the items the way I want. I'm drawing the thumbnail and the text below it as well as a rounded focus rectangle instead of the default stippled line rect.

    Qt Code:
    1. class QdIconView(QtGui.QListWidget):
    2. def __init__(self, parent=None):
    3. QtGui.QListWidget.__init__(self, parent)
    4.  
    5.  
    6. self.setIconSize(QtCore.QSize(160, 90)) # or setGridSize
    7. self.setViewMode(QtGui.QListView.IconMode)
    8. self.setMovement(QtGui.QListView.Static)
    9. self.setResizeMode(QtGui.QListView.Adjust) # re-lays out the items on resize
    10. self.setLayoutMode(QtGui.QListView.Batched) # does the layout with a timer for better performance
    11. self.setWrapping(True) # wraps the items to the next line so theres no horiz scrollbar
    12. self.setDragEnabled(True) # in case you want drag and drop
    13. self.setSpacing(1) # spacing between each item, buggy in Qt < 4.7 but works with small #'s
    To copy to clipboard, switch view to plain text mode 

Similar Threads

  1. HTML viewer
    By wj313 in forum Newbie
    Replies: 8
    Last Post: 13th June 2008, 19:02
  2. Problems with a thumbnail viewer for Konqueror
    By Valheru in forum KDE Forum
    Replies: 5
    Last Post: 22nd January 2008, 18:23

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.