Results 1 to 10 of 10

Thread: a set of images slide show on a single QLabel

  1. #1
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default a set of images slide show on a single QLabel

    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?

  2. #2
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    You have a label and you have a scrollbar.

    How do you react to the scrollbar changes?

    Cheers,
    _

  3. #3
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Smile Re: a set of images slide show on a single QLabel

    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.


    Quote Originally Posted by anda_skoa View Post
    You have a label and you have a scrollbar.

    How do you react to the scrollbar changes?

    Cheers,
    _

  4. #4
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    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,
    _

  5. #5
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    Quote Originally Posted by anda_skoa View Post
    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.

    Qt Code:
    1. void FindPeaks::on_nib_valueChanged(int value)
    2. {
    3. currImg = value+1;
    4. QString tmpn = QString::number(currImg);
    5. ui->currentimgnumber->setText(tmpn); //show the current number of image on the label currentimgnumber.
    6.  
    7. ui->originalimg->clear(); // originalimg is a label I want to show image on.
    8. ui->originalimg->setPixmap(QPixmap::fromImage(qimgset[value])); //qimgset is a vector that QImages were inside.
    9. ui->originalimg->repaint();
    10. ui->originalimg->show();
    11.  
    12.  
    13. }
    To copy to clipboard, switch view to plain text mode 

  6. #6
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    That looks good. The repaint() and show() shouldn't be necessary though.

    Do you see the current image number changing?

    Cheers,
    _

  7. #7
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    Quote Originally Posted by anda_skoa View Post
    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:


    Quote Originally Posted by lyw8120 View Post
    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;
    }
    Last edited by lyw8120; 17th March 2014 at 08:52.

  8. #8
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    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,
    _

  9. #9
    Join Date
    Oct 2012
    Posts
    7
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    Quote Originally Posted by anda_skoa View Post
    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.

  10. #10
    Join Date
    Jan 2006
    Location
    Graz, Austria
    Posts
    8,419
    Thanks
    37
    Thanked 1,546 Times in 1,496 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: a set of images slide show on a single QLabel

    Quote Originally Posted by lyw8120 View Post
    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,
    _

Similar Threads

  1. Replies: 1
    Last Post: 3rd January 2012, 21:15
  2. Slide show using QProperty animation
    By mvbhavsar in forum Newbie
    Replies: 0
    Last Post: 10th August 2011, 10:24
  3. Replies: 5
    Last Post: 16th December 2009, 11:33
  4. How to create filmstrip - multiple images in a single file
    By jessiemmichael in forum Qt Programming
    Replies: 1
    Last Post: 13th June 2008, 08:30
  5. slide show
    By jeetu_happy in forum Qt Programming
    Replies: 3
    Last Post: 18th January 2007, 12:21

Tags for this Thread

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.