rishiraj
7th May 2009, 10:54
Hi everyone,
I have a picture gallery application in which there are 8 QPushbuttons on top of which the pixmaps are set.On clicking the buttons(once the pixmaps are set on them),one can view them in enlarged form and do the usual things like rotate,zoomin/out etc.
My problem is that I have got more than 8 images in the picture folder so,I want to iterate over the images and display them in batches of 8...meaning,first time,it shows the first 8 images then after a couple of secs it shows the next 8 and so on till all the pics have been shown and then it again starts from the first 8 and goes on(till the user clicks on any of the pics to enlarge it).
I tried the following code:-
void Photogallery::createbuttons() //function called from constructor to create the
//8 pushbuttons
{
<<<<code to create the 8 buttons>>>
QDir CurrentDirectory("/root/Desktop/photos"); //'photos' dir. contains pictures
names= CurrentDirectory.entryList(QDir::Files|QDir::NoDot AndDotDot);
//'names' is a Qstringlist variable
timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(update() ));
timer->start();
}
void Mediagallery::update() //slot which sets up the images on buttons
{
it= names.begin(); //'it' is QStringlist iterator
int count=(names.size()/8);
for(int numimage=0;numimage<count;numimage++)
{
//first picture on first button.
QString Imagename(*it5);
firstImagepath = "/root/Desktop/photos/"+Imagename;
QPixmap imagedisplay(firstImagepath);
QIcon icon(imagedisplay);
firstImage->setIcon(icon); //firstImage is a Qpushbutton
connect(firstImage,SIGNAL(pressed()),this,SLOT(but tondown()));
//buttondown() is a slot where I identify which button is clicked.
//************************************************** *********
//second picture on second button
it5++;
QString Imagename2(*it5);
secondImagepath = "/root/Desktop/photos/"+Imagename2;
QPixmap imagedisplay2(secondImagepath);
secondImage->setIcon(imagedisplay2);
connect(secondImage,SIGNAL(pressed()),this,SLOT(bu ttondown()));
//************************************************** ***********
//third picture on third pushbutton
it5++;
QString Imagename3(*it5);
thirdImagepath= "/root/Desktop/photos/"+Imagename3;
QPixmap imagedisplay3(thirdImagepath);
thirdImage->setIcon(imagedisplay3);
connect(thirdImage,SIGNAL(pressed()),this,SLOT(but tondown()));
.........so on till 8th image is set.
QString numimagestr=QString::number(numimage);
QMessageBox::information(NULL,"",numimagestr); //keeping count
}
}
If I remove the 'QMessageBox' statement towards the end of the loop,all I get are eight empty pushbuttons (No pictures are set on them).If I keep the QMessageBox,I get the images in batches on the buttons(as expected) but,I cannot click on any of the pictures to enlarge it as the MessageBox keeps coming in the foreground.
I want the pics to show in batches of 8 without the presence of the MessageBox.
Any ideas on how to do that(maybe I need to change the logic) or use a Timer or something else at some point ....Need your advice on how to proceed.
Thank you.
I have a picture gallery application in which there are 8 QPushbuttons on top of which the pixmaps are set.On clicking the buttons(once the pixmaps are set on them),one can view them in enlarged form and do the usual things like rotate,zoomin/out etc.
My problem is that I have got more than 8 images in the picture folder so,I want to iterate over the images and display them in batches of 8...meaning,first time,it shows the first 8 images then after a couple of secs it shows the next 8 and so on till all the pics have been shown and then it again starts from the first 8 and goes on(till the user clicks on any of the pics to enlarge it).
I tried the following code:-
void Photogallery::createbuttons() //function called from constructor to create the
//8 pushbuttons
{
<<<<code to create the 8 buttons>>>
QDir CurrentDirectory("/root/Desktop/photos"); //'photos' dir. contains pictures
names= CurrentDirectory.entryList(QDir::Files|QDir::NoDot AndDotDot);
//'names' is a Qstringlist variable
timer=new QTimer(this);
connect(timer,SIGNAL(timeout()),this,SLOT(update() ));
timer->start();
}
void Mediagallery::update() //slot which sets up the images on buttons
{
it= names.begin(); //'it' is QStringlist iterator
int count=(names.size()/8);
for(int numimage=0;numimage<count;numimage++)
{
//first picture on first button.
QString Imagename(*it5);
firstImagepath = "/root/Desktop/photos/"+Imagename;
QPixmap imagedisplay(firstImagepath);
QIcon icon(imagedisplay);
firstImage->setIcon(icon); //firstImage is a Qpushbutton
connect(firstImage,SIGNAL(pressed()),this,SLOT(but tondown()));
//buttondown() is a slot where I identify which button is clicked.
//************************************************** *********
//second picture on second button
it5++;
QString Imagename2(*it5);
secondImagepath = "/root/Desktop/photos/"+Imagename2;
QPixmap imagedisplay2(secondImagepath);
secondImage->setIcon(imagedisplay2);
connect(secondImage,SIGNAL(pressed()),this,SLOT(bu ttondown()));
//************************************************** ***********
//third picture on third pushbutton
it5++;
QString Imagename3(*it5);
thirdImagepath= "/root/Desktop/photos/"+Imagename3;
QPixmap imagedisplay3(thirdImagepath);
thirdImage->setIcon(imagedisplay3);
connect(thirdImage,SIGNAL(pressed()),this,SLOT(but tondown()));
.........so on till 8th image is set.
QString numimagestr=QString::number(numimage);
QMessageBox::information(NULL,"",numimagestr); //keeping count
}
}
If I remove the 'QMessageBox' statement towards the end of the loop,all I get are eight empty pushbuttons (No pictures are set on them).If I keep the QMessageBox,I get the images in batches on the buttons(as expected) but,I cannot click on any of the pictures to enlarge it as the MessageBox keeps coming in the foreground.
I want the pics to show in batches of 8 without the presence of the MessageBox.
Any ideas on how to do that(maybe I need to change the logic) or use a Timer or something else at some point ....Need your advice on how to proceed.
Thank you.