Results 1 to 4 of 4

Thread: Load Images in a dir into a QScrollArea

  1. #1
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Load Images in a dir into a QScrollArea

    Hi,
    I'm trying to load all the images in the "images/" directory into a QScrollArea but I'm not sure how to add images into a QScrollArea. Or perhaps should I use QGraphicsView?

    I have a QStringList with all the images.

    I probably need to create a QLabel for every image in the dir and setPixmap for all of them.
    I'm just not sure on how to create the loop that iterates through QStringList and how to embed every QLabel into the QScrollArea (I only see setWidget but would that only embed one widget into it? )

    Thanks a lot in advance for any help you can provide.

  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: Load Images in a dir into a QScrollArea

    Qt Code:
    1. QWidget *viewport = new QWidget;
    2. QVBoxLayout *l = new QVBoxLayout(viewport);
    3. foreach(const QString &path, stringlist){
    4. QPixmap px(path);
    5. QLabel *label = new QLabel;
    6. label->setPixmap(px);
    7. l->addWidget(label);
    8. }
    9. scrollArea->setWidget(viewport);
    To copy to clipboard, switch view to plain text mode 

    This won't look very good but it's a place to start. Using QGraphicsView or QListView might give you better results though...

  3. The following user says thank you to wysota for this useful post:

    nmuntz (20th January 2009)

  4. #3
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load Images in a dir into a QScrollArea

    Thank you very much!
    That's exactly what I was looking for !
    Thanks again!

  5. #4
    Join Date
    May 2008
    Location
    USA
    Posts
    22
    Thanks
    4
    Thanked 2 Times in 2 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Load Images in a dir into a QScrollArea

    Hi,
    I'm just curious now:

    How could I handle each QLabel generated afterwards?
    I have a central QLabel which should change the pixmap to the image that I click by using the code in this example.

    Perhaps in the loop connect it to a signal that triggers a mousepressevent ?

    Thanks in advance for pointing me in the right direction.

Similar Threads

  1. WekKit won't load JPEG images.
    By andrem in forum Qt Programming
    Replies: 4
    Last Post: 10th December 2008, 00:24
  2. import large number of images
    By sriluyarlagadda in forum Qt Programming
    Replies: 5
    Last Post: 15th May 2008, 10:26
  3. Program not compiling on Fresh install of Leopard
    By dvmorris in forum Qt Programming
    Replies: 1
    Last Post: 22nd November 2007, 10:22
  4. Replies: 2
    Last Post: 8th October 2006, 20: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.