Results 1 to 7 of 7

Thread: How to display an image on a label from a folder containing images.

  1. #1
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default How to display an image on a label from a folder containing images.

    I have to display a number of images from a folder in bin onto a label or any other widget with an alterable frame rate??

  2. #2
    Join Date
    May 2010
    Posts
    30
    Thanks
    2
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: How to display an image on a label from a folder containing images.

    What have you tried?

  3. #3
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: How to display an image on a label from a folder containing images.

    thanx for showing concern...............................
    I am able to display a single image from a folder onto a label but don't know how to go beyond that. I mean how would I get a slide show kind of a thing??

  4. #4
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display an image on a label from a folder containing images.

    Have a look at QTimer

    Also if you are using 4.6.3, you have animation classes,, but try the timer thing first

  5. #5
    Join Date
    Feb 2010
    Posts
    68
    Thanks
    8
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display an image on a label from a folder containing images.

    Create a QTimer, connect its timeout() signal to the slot in which you'll change the images. In such slot you should use setPixmap function.
    Example:
    Qt Code:
    1. QTimer *slideShow = new QTimer(this);
    2. connect(slideShow,SIGNAL(timeout()),this,SLOT(changePixmap()));
    3. //...
    4. MainWindow::changePixmap()
    5. {
    6. ui.labelName.setPixmap(QPixmap("C:/path_to_image/imageName" + QString.setNum(imgNum) + ".ext")); //imgNum can be for example a private object of MainWindow class
    7. imgNum = (imgNum + 1) % 10 //for a series of 10 images with names "imageName(0-9).ext"
    8. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jul 2010
    Posts
    50
    Thanks
    7
    Platforms
    Windows

    Default Re: How to display an image on a label from a folder containing images.

    Quote Originally Posted by kremuwa View Post
    Create a QTimer, connect its timeout() signal to the slot in which you'll change the images. In such slot you should use setPixmap function.
    Example:
    Qt Code:
    1. QTimer *slideShow = new QTimer(this);
    2. connect(slideShow,SIGNAL(timeout()),this,SLOT(changePixmap()));
    3. //...
    4. MainWindow::changePixmap()
    5. {
    6. ui.labelName.setPixmap(QPixmap("C:/path_to_image/imageName" + QString.setNum(imgNum) + ".ext")); //imgNum can be for example a private object of MainWindow class
    7. imgNum = (imgNum + 1) % 10 //for a series of 10 images with names "imageName(0-9).ext"
    8. }
    To copy to clipboard, switch view to plain text mode 

    I have implemented it as :
    // MainWindow.cpp consists of this snippet:

    QTimer *timer = new QTimer;

    QStringList fileName = QFileDialog::getOpenFileNames(this,
    tr("Open Image"), "C:/qt-win-opensource-src-4.5.0/bin/", tr("Image Files (*.png *.jpg *.bmp *.avi *.gif)"));

    QStringListIterator iterator(fileName);
    label = new QLabel;
    connect(timer,SIGNAL(timeout()),this,SLOT(nextPict ure(QStringListIterator&)));
    timer->start(5000);


    //And the slot nextPicture is defined as:
    void MainWindow::nextPicture(QStringListIterator& iterator)
    {
    if(iterator.hasNext())
    {
    label->clear();
    label->setPixmap(QPixmap(iterator.next()));
    workspace->addWindow(label);
    label->show();
    }
    }
    But this is not displaying even a single image(which was getting displayed earlier).
    Thanx in advance.

  7. #7
    Join Date
    Oct 2006
    Location
    New Delhi, India
    Posts
    2,467
    Thanks
    8
    Thanked 334 Times in 317 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: How to display an image on a label from a folder containing images.

    connect(timer,SIGNAL(timeout()),this,SLOT(nextPict ure(QStringListIterator&)));
    You cannot connect that. It must be returning false.

    The slot MUST have equal to or less than arguments than the signal, and each argument matching like in functions..

Similar Threads

  1. How do i change images? Qt creator label>pixmap
    By QueenZ in forum Qt Programming
    Replies: 4
    Last Post: 8th February 2010, 04:44
  2. Replies: 1
    Last Post: 23rd May 2009, 09:04
  3. display number on label
    By aj2903 in forum Qt Programming
    Replies: 4
    Last Post: 12th March 2009, 07:24
  4. how to display micro(mu) symbol in label
    By babu198649 in forum Newbie
    Replies: 2
    Last Post: 7th March 2008, 10:59
  5. Display a Label on top of a QGlWidget
    By Lele in forum Qt Programming
    Replies: 3
    Last Post: 4th February 2008, 16: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.