PDA

View Full Version : a set of images slide show on a single QLabel



lyw8120
16th March 2014, 16:34
Dear all,

I want to let a qlabel to show many images one by one with the help of qscrollbar. But qlabel did not update and only show the first image.
I searched it by google, and the problem could be the layout, while confuse me, because I just want to show all the image on the same qlabel.

A QLabel was added by Qt Designer and showed the first image. so how to accomplish my goal?

anda_skoa
16th March 2014, 18:06
You have a label and you have a scrollbar.

How do you react to the scrollbar changes?

Cheers,
_

lyw8120
16th March 2014, 19:39
if the value of scrollbar is changed(signal is emited), then show the image, which its number in image set is the value of scrollbar.

for example, there are 40 images I want to show on the label. then the range of scrollbar is 1-40(actually 0-39).

I am not sure how to fresh the label. certainly it is the first time I am trying to design a GUI. so if you have suggestion, please tell me. thanks a lot.



You have a label and you have a scrollbar.

How do you react to the scrollbar changes?

Cheers,
_

anda_skoa
16th March 2014, 20:50
The general approach sounds right.

Do you have any code already that we could look at to determine where it goes wrong?

E.g. the slot that is connected tot the change signal?

Cheers,
_

lyw8120
17th March 2014, 08:06
The general approach sounds right.

Do you have any code already that we could look at to determine where it goes wrong?

E.g. the slot that is connected tot the change signal?

Cheers,
_

yes, this is my code.



void FindPeaks::on_nib_valueChanged(int value)
{
currImg = value+1;
QString tmpn = QString::number(currImg);
ui->currentimgnumber->setText(tmpn); //show the current number of image on the label currentimgnumber.

ui->originalimg->clear(); // originalimg is a label I want to show image on.
ui->originalimg->setPixmap(QPixmap::fromImage(qimgset[value])); //qimgset is a vector that QImages were inside.
ui->originalimg->repaint();
ui->originalimg->show();


}

anda_skoa
17th March 2014, 08:17
That looks good. The repaint() and show() shouldn't be necessary though.

Do you see the current image number changing?

Cheers,
_

lyw8120
17th March 2014, 08:52
That looks good. The repaint() and show() shouldn't be necessary though.

Do you see the current image number changing?

Cheers,
_
yes ,it changed.
the image does not fresh even there is operation of repaint and show.

Added after 19 minutes:


yes ,it changed.
the image does not fresh even there is operation of repaint and show.

I found a problem, it cannot show the other image after I changed the number manually(for example, 30), it still shows the same image.

I check the qimgset, it indeed has 40 elements.

then I check the code how to read image, I found the problem.



for(int i=0; i<filenamelist.size();++i)
{
filenamelist[i] = pathname + "/"+filenamelist[i];
Mat img = imread(filenamelist[i].toAscii().data(),0);
imgset.push_back(img);

QImage qimg;
qimg.load(filenamelist[0]); //here, it should be i, not 0, I forgot to change it(I just want to make a test at that time).
qimgset.push_back(qimg);
}

it is working now. thanks a lot for your help.

I have another question.
why it cannot show image of Mat(Opencv class), I convert it to qimage like this. it shows nothing, and totally different with the effect of qimage.



QImage Mat2QImage(Mat & src)
{
Mat temp(src.cols,src.rows,src.type());
cvtColor(src,temp,CV_GRAY2RGB);
//imshow("test",temp);
// waitKey(0);

QImage dest = QImage((const unsigned char*)(temp.data),temp.cols,temp.rows,temp.step,QI mage::Format_Indexed8);
return dest;
}

anda_skoa
17th March 2014, 10:38
My guess is that temp releases the image memory when it goes out of scope, leaving dest without valid image memory to point to.

Cheers,
_

lyw8120
17th March 2014, 11:36
My guess is that temp releases the image memory when it goes out of scope, leaving dest without valid image memory to point to.

Cheers,
_

temp is OK, the code I commented was working. the QImage dest did not show the correct result.

my image is grayscale image. temp shows the right way, but dest.

anda_skoa
17th March 2014, 13:19
temp is OK, the code I commented was working.

The code you've commented out is working with temp while it is still in scope.
The QImage dest is returned, it needs to be able to address the memory when temp has long gone.

Are you sure that temp does not delete its data when it is deleted?

Cheers,
_