View Full Version : How to display an image on a label from a folder containing images.
qt_user
28th July 2010, 16:25
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??
grabalon
28th July 2010, 16:30
What have you tried?
qt_user
29th July 2010, 06:28
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??
aamer4yu
29th July 2010, 07:32
Have a look at QTimer
Also if you are using 4.6.3, you have animation classes,, but try the timer thing first :)
kremuwa
29th July 2010, 07:58
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:
QTimer *slideShow = new QTimer(this);
connect(slideShow,SIGNAL(timeout()),this,SLOT(chan gePixmap()));
//...
MainWindow::changePixmap()
{
ui.labelName.setPixmap(QPixmap("C:/path_to_image/imageName" + QString.setNum(imgNum) + ".ext")); //imgNum can be for example a private object of MainWindow class
imgNum = (imgNum + 1) % 10 //for a series of 10 images with names "imageName(0-9).ext"
}
qt_user
30th July 2010, 06:25
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:
QTimer *slideShow = new QTimer(this);
connect(slideShow,SIGNAL(timeout()),this,SLOT(chan gePixmap()));
//...
MainWindow::changePixmap()
{
ui.labelName.setPixmap(QPixmap("C:/path_to_image/imageName" + QString.setNum(imgNum) + ".ext")); //imgNum can be for example a private object of MainWindow class
imgNum = (imgNum + 1) % 10 //for a series of 10 images with names "imageName(0-9).ext"
}
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.
aamer4yu
30th July 2010, 07:23
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..
Powered by vBulletin® Version 4.2.5 Copyright © 2024 vBulletin Solutions Inc. All rights reserved.