Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. Which Qt signal is triggerred when 2D image is completely updated on QGraphicalScene
Forum Update on Monday, May 27th 2025

Which Qt signal is triggerred when 2D image is completely updated on QGraphicalScene

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    saurabh162
    wrote on last edited by saurabh162
    #1

    Dear Developers,

    In my application, I need to repeatedly update fix size 2D Image (as shown below) using data from DMD (Digital micromirror device ). And once plotting of 2D image gets completed on 2D Graphic area, I need to automatically trigger snap shot of my PC screen and save this image.
    DMD_Output.png

    So can you please inform which Qt Widget can I use for this purpose?

    Whether QGraphicalScene widget is suitable for it? If yes then can you please inform me which signal can I use in QGraphicalScene widget to trigger automatically Screenshot of my screen once plotting from DMD data is completed.

    Kindly inform me if you need any other information from me.
    Thanks !!

    JonBJ 1 Reply Last reply
    0
    • S saurabh162

      Dear Developers,

      In my application, I need to repeatedly update fix size 2D Image (as shown below) using data from DMD (Digital micromirror device ). And once plotting of 2D image gets completed on 2D Graphic area, I need to automatically trigger snap shot of my PC screen and save this image.
      DMD_Output.png

      So can you please inform which Qt Widget can I use for this purpose?

      Whether QGraphicalScene widget is suitable for it? If yes then can you please inform me which signal can I use in QGraphicalScene widget to trigger automatically Screenshot of my screen once plotting from DMD data is completed.

      Kindly inform me if you need any other information from me.
      Thanks !!

      JonBJ Offline
      JonBJ Offline
      JonB
      wrote on last edited by
      #2

      @saurabh162
      There will not be such a specific signal. Create your own, emit it when "image completed", attach slot to do desired "screenshot".

      1 Reply Last reply
      1
      • S Offline
        S Offline
        saurabh162
        wrote on last edited by
        #3

        @JonB Thank you very much for your answer. Can you please inform me whether QGraphicalScene is good choice for this type of application (updating 2D matrix using data from DMD as shown in attached picture) or shall I consider some other Qt widget for this purpose ?

        Thanks !!

        1 Reply Last reply
        0
        • C Offline
          C Offline
          ChrisW67
          wrote on last edited by
          #4

          I am confused, if you are updating the image then you already know when you are finished. In any case, it seems like an odd design decision to capture the result in a screen shot when you have everything you need to build and store a result image directly.

          1 Reply Last reply
          0
          • S Offline
            S Offline
            saurabh162
            wrote on last edited by saurabh162
            #5

            @ChrisW67, thank you very much for reply and queries..

            I try to answer to your questions :)

            Q) I am confused, if you are updating the image then you already know when you are finished ?

            Ans) Yes you are right it can be confusing.

            But practically when you draw a pattern on your PC Screen(I have tested using “chip” example in Qt library) using “QGraphicalView” widget, by sending some data and takes screen shot immediately after you have set scene(or transmitted complete data to PC screen) in QGraphicalView in your software using following instructions:

            view->view()->setScene(scene);
            triggerSignalForScreenShot();
            

            Then as a result you get a screen shot of your application, just when it has started plotting your data on your monitor and not at the time it has finished plotting your data on your monitor.

            Below I have attached actual and expected screen shot for my application.

            Actual Screen Shot
            GetScreenShot.png

            Expected Screen Shot

            ExpectedScreenShot.png

            In other words there a delay between setting a Scene in your software and when the scene actually get displayed on your monitor due to which screen shot get triggered before data is displayed on monitor.

            Q) In any case, it seems like an odd design decision to capture the result in a screen shot when you have everything you need to build and store a result image directly?

            Ans) Again I agree with you if I have see it as a individual project 😊

            But in fact this application will be one of the component of complex automated system, where high speed cameras will be triggered(taking screen shot ) day and night capturing output from sensors displayed on screen. The images taken from camera will be compared in this system with some reference images and further action will be automatically triggered if captured images matches reference images.

            I hope that I answered your doubts, please inform me if you need any other information.

            @JonB B I have tried as you mentioned but i do know how to find out when plotting of image on screen is completed. As there is a delay between when I send data from my software and when it is actually displayed on screen. Can you please inform me about any signal which i can use to know that my image has been displayed completely on screen.

            1 Reply Last reply
            0
            • SGaistS Offline
              SGaistS Offline
              SGaist
              Lifetime Qt Champion
              wrote on last edited by
              #6

              Hi,

              Why would you do screenshots ?
              What format are you reference images ?
              From what you wrote, you need to rebuild a proper image from your camera data and then maybe convert that to the same format as your reference images or if your reference images are already loaded in memory, transform your camera data to the same colorspace than your reference images to do the comparison.

              Interested in AI ? www.idiap.ch
              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

              1 Reply Last reply
              0
              • S Offline
                S Offline
                saurabh162
                wrote on last edited by saurabh162
                #7

                @SGaist Thank you very much for answer. Following I try to answer your questions and if in case i miss anything please let me know.

                Q) Why would you do screenshots ?
                Ans) Because I need to save picture of data(received from sensor) displayed on screen.

                What format are you reference images ?
                Ans) right now .png but if you think any other format can better solve problem mentioned above then please suggest me I will take that format.

                Q) From what you wrote, you need to rebuild a proper image from your camera data and then maybe convert that to the same format as your reference images or if your reference images are already loaded in memory, transform your camera data to the same colorspace than your reference images to do the comparison.

                Ans) Sorry if my topic of this post is not clear enough or created miss understanding.

                Problem is not: that I do not know, how to process captured image from camera in order to compare it with my reference image.
                Problem is: right now when I trigger screenshot/camera capture signal from my software, immediately after setting scene in QGraphicalView widget in my software as mentioned below.

                view->view()->setScene(scene);
                triggerSignalForScreenShot();
                

                then the screen shot I get is of my PC screen before data is actually plotted on Screen (in QGraphicalView). As there is a delay between the time when data is set in QGraphicaView in software and the time when it is rendered on screen in reality.

                JonBJ 1 Reply Last reply
                0
                • S saurabh162

                  @SGaist Thank you very much for answer. Following I try to answer your questions and if in case i miss anything please let me know.

                  Q) Why would you do screenshots ?
                  Ans) Because I need to save picture of data(received from sensor) displayed on screen.

                  What format are you reference images ?
                  Ans) right now .png but if you think any other format can better solve problem mentioned above then please suggest me I will take that format.

                  Q) From what you wrote, you need to rebuild a proper image from your camera data and then maybe convert that to the same format as your reference images or if your reference images are already loaded in memory, transform your camera data to the same colorspace than your reference images to do the comparison.

                  Ans) Sorry if my topic of this post is not clear enough or created miss understanding.

                  Problem is not: that I do not know, how to process captured image from camera in order to compare it with my reference image.
                  Problem is: right now when I trigger screenshot/camera capture signal from my software, immediately after setting scene in QGraphicalView widget in my software as mentioned below.

                  view->view()->setScene(scene);
                  triggerSignalForScreenShot();
                  

                  then the screen shot I get is of my PC screen before data is actually plotted on Screen (in QGraphicalView). As there is a delay between the time when data is set in QGraphicaView in software and the time when it is rendered on screen in reality.

                  JonBJ Offline
                  JonBJ Offline
                  JonB
                  wrote on last edited by JonB
                  #8

                  @saurabh162
                  Depends how your triggerSignalForScreenShot(); is implemented, about which you say nothing. It's not that there is some hidden delay, per se, it's (presumably) that the view has not been given its chance to render, through the Qt event loop.

                  Which is why choosing to call e.g.
                  void QGraphicsView::render(QPainter *painter, const QRectF &target = QRectF(), const QRect &source = QRect(), Qt::AspectRatioMode aspectRatioMode = Qt::KeepAspectRatio)

                  Renders the source rect, which is in view coordinates, from the scene into target, which is in paint device coordinates, using painter. This function is useful for capturing the contents of the view onto a paint device, such as a QImage (e.g., to take a screenshot), or for printing to QPrinter. For example:

                  (or same on QGraphicsScene rather than QGraphicsView if you prefer) would avoid this issue and seem much better to me?

                  P.S.
                  If, for whatever reason, you are determined to use some external screenshotter you will need to get the view rendered. The easiest is to try calling view->view()->repaint() immediately before your triggerSignalForScreenShot();. Or you move that (the screenshot call) into something like the QWidget::paintEvent() for the view and allow code to enter the Qt event loop. I'm not certain whether there are any better calls for a gfx scene/view, but the above is for a general QWidget, which a QGraphicsView is.

                  1 Reply Last reply
                  1
                  • S Offline
                    S Offline
                    saurabh162
                    wrote on last edited by
                    #9

                    @JonB many many thanks for answer....I will try what you suggest and will update you ..Thanks :)

                    JonBJ 1 Reply Last reply
                    0
                    • S saurabh162

                      @JonB many many thanks for answer....I will try what you suggest and will update you ..Thanks :)

                      JonBJ Offline
                      JonBJ Offline
                      JonB
                      wrote on last edited by JonB
                      #10

                      @saurabh162
                      It's a bit ugly, but like I said if you don't care the absolute minimum change to just try and see if you get what you want would be:

                      view->view()->setScene(scene);
                      view->view()->repaint();
                      triggerSignalForScreenShot();
                      

                      Does that at least do what you want, at least then I understand. Though I still think the QGraphicsView::render() call to produce a QImage would seem to me what you really ought be doing.

                      1 Reply Last reply
                      0
                      • S Offline
                        S Offline
                        saurabh162
                        wrote on last edited by saurabh162
                        #11

                        @JonB once again thanks for your response. I have tried following code to do what you suggested

                        view->view()->setScene(scene);
                         view->show();
                          QPrinter printer(QPrinter::HighResolution);
                          printer.pageLayout().pageSize();
                         QPainter painter(&printer);
                        
                         // print, fitting the viewport contents into a full page
                          view->render(&painter);
                          triggerSignalForScreenShot();
                        

                        but still I getting the result/problem as mentioned above.

                        triggerSignalForScreenShot()
                        

                        is user defined signal which I connect to its slot using :

                        connect(this,&MainWindow::triggerSignalForScreenShot,
                                      this, &MainWindow::sceneChanged);
                        

                        and slot I defined as follows:

                        void MainWindow::sceneChanged( )
                        {
                            shootScreen();
                            saveScreenshot();
                        }
                        

                        Thanks !! and kindly inform me if you need any other information or if I am making any mistake.

                        JonBJ 1 Reply Last reply
                        0
                        • S saurabh162

                          @JonB once again thanks for your response. I have tried following code to do what you suggested

                          view->view()->setScene(scene);
                           view->show();
                            QPrinter printer(QPrinter::HighResolution);
                            printer.pageLayout().pageSize();
                           QPainter painter(&printer);
                          
                           // print, fitting the viewport contents into a full page
                            view->render(&painter);
                            triggerSignalForScreenShot();
                          

                          but still I getting the result/problem as mentioned above.

                          triggerSignalForScreenShot()
                          

                          is user defined signal which I connect to its slot using :

                          connect(this,&MainWindow::triggerSignalForScreenShot,
                                        this, &MainWindow::sceneChanged);
                          

                          and slot I defined as follows:

                          void MainWindow::sceneChanged( )
                          {
                              shootScreen();
                              saveScreenshot();
                          }
                          

                          Thanks !! and kindly inform me if you need any other information or if I am making any mistake.

                          JonBJ Offline
                          JonBJ Offline
                          JonB
                          wrote on last edited by JonB
                          #12

                          @saurabh162 said in Which Qt signal is triggerred when 2D image is completely updated on QGraphicalScene:

                          view->render(&painter);
                          triggerSignalForScreenShot();

                          As per the docs this renders the view into the painter you pass to render(), from which it says you can produce a QImage. I have no idea what you think you are doing by ignoring this and calling your original triggerSignalForScreenShot(), what does that have to do with it?

                          I also suggested you try the simplest current "fix" by putting in a view->view()->repaint(); initially and seeing that delivers what you want, but you don't seem to have looked at that.

                          I leave it to you now, I have helped all I can.

                          1 Reply Last reply
                          0
                          • S Offline
                            S Offline
                            saurabh162
                            wrote on last edited by saurabh162
                            #13

                            @JonB Thank you !! Actually I have tried view->view()->repaint(); solution provided by you. but it did not help and after that I have tried solution I have pasted in my previous post.

                            And about " triggerSignalForScreenShot()" signal I have used because I did not understand how I can pass QImage to render() so that it produce image of screen(Sorry I am newbie in Qt).

                            But many thanks for your help ..I will now try/see how i can pass QImage object in render() function. Thank you !!

                            1 Reply Last reply
                            0
                            • SGaistS Offline
                              SGaistS Offline
                              SGaist
                              Lifetime Qt Champion
                              wrote on last edited by
                              #14

                              I am still curious about your need to do the capture of the shown image for comparison rather that do the comparison directly with the image you rebuilt from the camera data.

                              Interested in AI ? www.idiap.ch
                              Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                              S 1 Reply Last reply
                              0
                              • SGaistS SGaist

                                I am still curious about your need to do the capture of the shown image for comparison rather that do the comparison directly with the image you rebuilt from the camera data.

                                S Offline
                                S Offline
                                saurabh162
                                wrote on last edited by
                                #15

                                @SGaist sorry I could not understand your question....whether you want to ask, why I want to capture image using camera ? instead of directly comparing images with my reference images directly ?

                                SGaistS 1 Reply Last reply
                                0
                                • S Offline
                                  S Offline
                                  saurabh162
                                  wrote on last edited by
                                  #16

                                  @JonB @ChrisW67 @SGaist ...I am now able to save snapshot of image I display using "QGraphicsScene" using method mentioned by @JonB .

                                  In order to save image in .png format. i have used following code.

                                  // Save rendered image in a .png file

                                  ```
                                  

                                  QImage image(11000,7000, QImage::Format_RGB32);

                                  QPainter painter(&image);
                                  scene->render(&painter);
                                  painter.setRenderHints(QPainter::Antialiasing | QPainter::SmoothPixmapTransform);
                                  image.mirrored().save("output.png");
                                  
                                  
                                  many thanks for your help !!
                                  1 Reply Last reply
                                  0
                                  • S saurabh162

                                    @SGaist sorry I could not understand your question....whether you want to ask, why I want to capture image using camera ? instead of directly comparing images with my reference images directly ?

                                    SGaistS Offline
                                    SGaistS Offline
                                    SGaist
                                    Lifetime Qt Champion
                                    wrote on last edited by
                                    #17

                                    @saurabh162 said in Which Qt signal is triggerred when 2D image is completely updated on QGraphicalScene:

                                    @SGaist sorry I could not understand your question....whether you want to ask, why I want to capture image using camera ? instead of directly comparing images with my reference images directly ?

                                    No no, I am wondering about the "capture the scene" step rather than directly save the built image.

                                    Interested in AI ? www.idiap.ch
                                    Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                    1 Reply Last reply
                                    0
                                    • S Offline
                                      S Offline
                                      saurabh162
                                      wrote on last edited by
                                      #18

                                      @SGaist Capturing image(pattern provided by DMDs(Digital micromirror device)) is important in our case to adjust output from DMDs ( feedback loop ) which will be connected to camera responsible to take pictures on screen.

                                      We cannot give feedback to DMDs directly from our PC due to technical reasons...please inform me if i have not answered your question....Thanks !!

                                      1 Reply Last reply
                                      0
                                      • SGaistS Offline
                                        SGaistS Offline
                                        SGaist
                                        Lifetime Qt Champion
                                        wrote on last edited by
                                        #19

                                        You are at the wrong end of the system for my question.

                                        I have no issue with the act of capturing that image for your feedback loop. My question is really, why do need to the detour through the painting of the QGraphicsScene rather than simply save the image you built from the camera to disk ? That would likely give you a higher quality image.

                                        Interested in AI ? www.idiap.ch
                                        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

                                        1 Reply Last reply
                                        1

                                        • Login

                                        • Login or register to search.
                                        • First post
                                          Last post
                                        0
                                        • Categories
                                        • Recent
                                        • Tags
                                        • Popular
                                        • Users
                                        • Groups
                                        • Search
                                        • Get Qt Extensions
                                        • Unsolved