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. How can I make sure that paintEvent has finished?

How can I make sure that paintEvent has finished?

Scheduled Pinned Locked Moved Unsolved General and Desktop
5 Posts 3 Posters 497 Views 2 Watching
  • 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.
  • J Offline
    J Offline
    JamalNewtron
    wrote on last edited by
    #1

    Hi,

    in my applicaiton I am invoking the paintEvent through the udpate() methode. Inside the paintEvent I am using a painter to draw a rectangle. After each invocation of the update() methode I am changing the coordinates so that the rectangle is moved meandering through the widget. After each move of the rectangle I need to take a picture of the screen through a camera which is positioned in the front of the monitor. The code for taking pictures is running on a separate thread. GUI-Thread and "camera"-Thread are synchronized through a conditional variable.

    Now I have some problems in synchronizing between the threads. It happens that I am taking two pictures of the same rectangle position and afterwards the rectangle moves twice...

    I think it has something to do with the paintEvent and the conditional variable. How can I make sure that paintEvent has finished (rectangle is moved!). I also need to somehow filter that paintEvent has finished based on my invocation of the update() methode and not something different triggering the paintEvent.

    Thank you a lot!

    M Axel SpoerlA 2 Replies Last reply
    0
    • J JamalNewtron

      Hi,

      in my applicaiton I am invoking the paintEvent through the udpate() methode. Inside the paintEvent I am using a painter to draw a rectangle. After each invocation of the update() methode I am changing the coordinates so that the rectangle is moved meandering through the widget. After each move of the rectangle I need to take a picture of the screen through a camera which is positioned in the front of the monitor. The code for taking pictures is running on a separate thread. GUI-Thread and "camera"-Thread are synchronized through a conditional variable.

      Now I have some problems in synchronizing between the threads. It happens that I am taking two pictures of the same rectangle position and afterwards the rectangle moves twice...

      I think it has something to do with the paintEvent and the conditional variable. How can I make sure that paintEvent has finished (rectangle is moved!). I also need to somehow filter that paintEvent has finished based on my invocation of the update() methode and not something different triggering the paintEvent.

      Thank you a lot!

      M Offline
      M Offline
      mpergand
      wrote on last edited by mpergand
      #2

      Hi @JamalNewtron ,

      There's an alternative to update(), it's to call repaint(), it initiates a instant redraw of the widget instead of passing through the event loop.
      Maybe worth a try ?

      1 Reply Last reply
      0
      • J JamalNewtron

        Hi,

        in my applicaiton I am invoking the paintEvent through the udpate() methode. Inside the paintEvent I am using a painter to draw a rectangle. After each invocation of the update() methode I am changing the coordinates so that the rectangle is moved meandering through the widget. After each move of the rectangle I need to take a picture of the screen through a camera which is positioned in the front of the monitor. The code for taking pictures is running on a separate thread. GUI-Thread and "camera"-Thread are synchronized through a conditional variable.

        Now I have some problems in synchronizing between the threads. It happens that I am taking two pictures of the same rectangle position and afterwards the rectangle moves twice...

        I think it has something to do with the paintEvent and the conditional variable. How can I make sure that paintEvent has finished (rectangle is moved!). I also need to somehow filter that paintEvent has finished based on my invocation of the update() methode and not something different triggering the paintEvent.

        Thank you a lot!

        Axel SpoerlA Offline
        Axel SpoerlA Offline
        Axel Spoerl
        Moderators
        wrote on last edited by
        #3

        @JamalNewtron
        It depends on your operating system, how a screen asset is actually rendered onto the screen. With the info about your app being a bit too general for exact instructions, I propose to emit a signal to the camera thread, when the painting has been done.

        That can be achieved with an event filter or by subclassing the widget and overriding its paint event. You can emit a signal after having called the paint event of the base class.

        The limitation is, that the drawing happens into a backing store.
        That may be flushed to the screen asynchronously e.g. on Linux/X11.
        So even when the paint event has been completed, the display manager may still flush it at a later point.

        Software Engineer
        The Qt Company, Oslo

        1 Reply Last reply
        2
        • J Offline
          J Offline
          JamalNewtron
          wrote on last edited by
          #4

          @mpergand: Will give it a try. Thanks a lot.
          @Axel-Spoerl: I think that is what I am experiencing. After the paintEvent or the painter.end() method the monitor is not instantly refreshing. I am using Windows 11. Is there any option to get to know when the screen has been flushed?

          Axel SpoerlA 1 Reply Last reply
          0
          • J JamalNewtron

            @mpergand: Will give it a try. Thanks a lot.
            @Axel-Spoerl: I think that is what I am experiencing. After the paintEvent or the painter.end() method the monitor is not instantly refreshing. I am using Windows 11. Is there any option to get to know when the screen has been flushed?

            Axel SpoerlA Offline
            Axel SpoerlA Offline
            Axel Spoerl
            Moderators
            wrote on last edited by
            #5

            @JamalNewtron said in How can I make sure that paintEvent has finished?:

            Is there any option to get to know when the screen has been flushed?

            My Windows knowledge is very limited. From what I know, things a pretty synchronous on Windows. The issue you experience is not Qt related. It applies to all windows in Windows.

            Software Engineer
            The Qt Company, Oslo

            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