Results 1 to 13 of 13

Thread: refresh image in a Qlabel

  1. #1
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default refresh image in a Qlabel

    I have set an image using Qlabel as:
    Qt Code:
    1. ui->label->setPixmap(QPixmap("/home/hls/Grab-build-desktop-Qt_4_8_1_in_PATH__System__Debug/rgb.bmp"));
    To copy to clipboard, switch view to plain text mode 

    I am performing some image processing tasks,so I want to refresh my image continuously.
    Currently it is showing the image which appears at the start of the application.
    The application changes the image,and I want to change the image continuously in the label

    How can i Do that?

  2. #2
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: refresh image in a Qlabel

    Make QPixmap as class member and reset image QLabel::setPixmap when the image has been changed.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  3. #3
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: refresh image in a Qlabel

    I am sorry,but couldn't understand by "Make QPixmap as class member".
    I have now reset the image everytime after the image has changed.
    It's only a temporary fix.
    Isn't there anything where I only have to give the refernce of the file and the QLabel changes automatically whenever the picture changes.

  4. #4
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: refresh image in a Qlabel

    Quote Originally Posted by prkhr4u
    I am sorry,but couldn't understand by "Make QPixmap as class member".
    Declare QPixmap it in the header file as a private or public... member and initialize or define it in your .cpp file then you might be able to find an approach to solve your problem.

    Good Luck.

  5. #5
    Join Date
    Aug 2008
    Location
    Ukraine, Krivoy Rog
    Posts
    1,963
    Thanked 370 Times in 336 Posts
    Qt products
    Qt3 Qt4 Qt5
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: refresh image in a Qlabel

    Quote Originally Posted by prkhr4u View Post
    Isn't there anything where I only have to give the refernce of the file and the QLabel changes automatically whenever the picture changes.
    No, there is not anything something like this. QLabel doesn't keep track of QPixmap changes, you have to reset the pixmap each time it has been changed in order to make correct rendering by QLabel.
    Qt Assistant -- rocks!
    please, use tags [CODE] & [/CODE].

  6. The following user says thank you to spirit for this useful post:

    prkhr4u (19th October 2013)

  7. #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: refresh image in a Qlabel

    Quote Originally Posted by prkhr4u View Post
    I am performing some image processing tasks,so I want to refresh my image continuously.
    Do you perform those processing steps outside the displaying application?

    Cheers,
    _

  8. #7
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: refresh image in a Qlabel

    No,the processing is performed in a seperate thread,but in the same application

  9. #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: refresh image in a Qlabel

    Then you could just set the updated image on the label whenever your thread has signalled that it is finished.

    No need to go through saving/loading a file, just creating a QPixmap from the QImage you are working on.

    Cheers,
    _

  10. #9
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: refresh image in a Qlabel

    Have done something similar, reset the image everytime the processing completes.
    But as the application is continuous running, the thread never finishes..but only on application exit.

  11. #10
    Join Date
    Dec 2012
    Posts
    197
    Thanks
    25
    Thanked 41 Times in 33 Posts
    Qt products
    Qt4 Qt5
    Platforms
    Unix/X11 Windows

    Default Re: refresh image in a Qlabel

    Quote Originally Posted by prkhr4u View Post
    But as the application is continuous running, the thread never finishes..but only on application exit.
    If its a worker thread then you are doing something wrong and you have to go over the thread class and the threads object creation to figure it out.
    When the Process that the thread is responsible for is done, delete the threads object and catch the threads finish signal.(you can emit your own finish signal).

    Good Luck.

  12. #11
    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: refresh image in a Qlabel

    Quote Originally Posted by prkhr4u View Post
    Have done something similar, reset the image everytime the processing completes.
    But as the application is continuous running, the thread never finishes..but only on application exit.
    How is that related to your goal of updating the image?
    Does your thread never finish processing the image?

    Cheers,
    _

  13. #12
    Join Date
    Oct 2013
    Location
    Bangalore,India
    Posts
    64
    Thanks
    21
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: refresh image in a Qlabel

    I have one GUI thread and one worker thread. Whenever I signal 'start' from GUI thread the processing starts in worker thread and whenever I signal 'stop' the processing in worker thread stops.
    After signalling 'stop' the image has to be refreshed in the GUI,
    But the image processing code of start and stop code has been enclosed in a while(1) loop,hence the thread never exits..but only on the application exit.
    I need to process the image every 2-3 seconds,hence i have let the thread run thorughout the application.

  14. #13
    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: refresh image in a Qlabel

    Ok, but that has no relation to the image processing being done at some point, i.e. when you signal stop.
    The thread stops accessing the image and you use it to update the label.

    Cheers,
    _

Similar Threads

  1. Where can Qlabel keep its image?
    By hind in forum Qt Programming
    Replies: 3
    Last Post: 15th July 2013, 04:11
  2. Image in QLabel not being displayed
    By P@u1 in forum Qt Programming
    Replies: 2
    Last Post: 4th July 2011, 10:47
  3. Replies: 2
    Last Post: 14th January 2011, 16:09
  4. Replies: 6
    Last Post: 21st September 2009, 11:55
  5. QLabel as an image.
    By RSX in forum Newbie
    Replies: 2
    Last Post: 4th April 2009, 20:22

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.