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. Drawing rectangles every 50 ms
Qt 6.11 is out! See what's new in the release blog

Drawing rectangles every 50 ms

Scheduled Pinned Locked Moved Solved General and Desktop
19 Posts 4 Posters 1.7k Views 1 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.
  • H HappyVisualizer

    @SGaist Thanks for your help.

    What do you exactly mean with shuffling? I can imagine that you can draw them all at the beginning and only change the color for all rectangles. However, then you still would need to iterate over all the rectangles, changing their colors. Is that what you mean?

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

    @HappyVisualizer i meant shuffling their positions.

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

    H 1 Reply Last reply
    0
    • SGaistS SGaist

      @HappyVisualizer i meant shuffling their positions.

      H Offline
      H Offline
      HappyVisualizer
      wrote on last edited by
      #7

      @SGaist Thanks for clarifying. So using a simple setpos() for each rectangle? Or do you suggest other functions / functionality? I'm really stuck at the moment..

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

        No no, setPos is fine for that.

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

        H 1 Reply Last reply
        0
        • SGaistS SGaist

          No no, setPos is fine for that.

          H Offline
          H Offline
          HappyVisualizer
          wrote on last edited by HappyVisualizer
          #9

          @SGaist Thanks a lot for your reply. It's been a while, but I did some testing and it seems that every time when calling setSceneRect(...), the paint function for all QGraphicsRectItems are being called. Is this indeed the case and instead of changing the coordinates of the scene every time (by going from [0, x] to [x, 2x] using setSceneRect(...)), is setPos(x,y) for each QGraphicsRectItem then faster and should I just change the positions of all these items in the scene, relative to the scene (and making sure 'old' rectangles are removed from the scene)?

          And in that case, would QT be able to do this setPos() for 100,000 rectangles within 50 milliseconds? The idea behind the 100,000 rectangles is that we roughly 1.5h of data shown. Each rectangle has a width of 50 ms and each 50 ms, a new rectangle of data arrives. This pushes out the oldest rectangle, and would insert the newest rectangle. Thus, ((1.5 * 60 * 60 * 1000) / 50) = 108,000 objects where we need to apply setPos every 50 ms.

          JonBJ 1 Reply Last reply
          0
          • H HappyVisualizer

            @SGaist Thanks a lot for your reply. It's been a while, but I did some testing and it seems that every time when calling setSceneRect(...), the paint function for all QGraphicsRectItems are being called. Is this indeed the case and instead of changing the coordinates of the scene every time (by going from [0, x] to [x, 2x] using setSceneRect(...)), is setPos(x,y) for each QGraphicsRectItem then faster and should I just change the positions of all these items in the scene, relative to the scene (and making sure 'old' rectangles are removed from the scene)?

            And in that case, would QT be able to do this setPos() for 100,000 rectangles within 50 milliseconds? The idea behind the 100,000 rectangles is that we roughly 1.5h of data shown. Each rectangle has a width of 50 ms and each 50 ms, a new rectangle of data arrives. This pushes out the oldest rectangle, and would insert the newest rectangle. Thus, ((1.5 * 60 * 60 * 1000) / 50) = 108,000 objects where we need to apply setPos every 50 ms.

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

            @HappyVisualizer
            Yes to all that. Changing the whole scene rectangle will presumably repaint the whole scene, changing individual items redraws just them (and whatever they uncover).

            H 1 Reply Last reply
            0
            • JonBJ JonB

              @HappyVisualizer
              Yes to all that. Changing the whole scene rectangle will presumably repaint the whole scene, changing individual items redraws just them (and whatever they uncover).

              H Offline
              H Offline
              HappyVisualizer
              wrote on last edited by
              #11

              @JonB Thanks for your reply. I just tested this as follows:

              for(auto& scene_item : scene()->items())
                  {
                      if (scene_item->type() == SampleRectangle::Type)
                      {
                          SampleRectangle *rect_item = dynamic_cast<SampleRectangle*>( scene_item );
              
              
                          if (rect_item->get_time() < min_time)
                          {
                              scene()->removeItem(scene_item);
                          }
              
                          else 
                          {
                              scene_item->setPos( width() * ((double)(rect_item->get_time() - min_time) / (double)(max_time - min_time)), 0);
                          }
                          
                      }
                  }
              

              The code checks if the rectangle item is outside the screen (by determining whether its time is lower than the current displayed minimum time) and else, we update the position of the rectangle in the scene. However, printing a counter in the paint() method of the QRectItem, I still see the counter incrementing, indicating the the paint() method is called everytime the setPos() function is called. I'm using Qt5 by the way. Do you know why paint() is still called for every setPos()?

              JonBJ 1 Reply Last reply
              0
              • H HappyVisualizer

                @JonB Thanks for your reply. I just tested this as follows:

                for(auto& scene_item : scene()->items())
                    {
                        if (scene_item->type() == SampleRectangle::Type)
                        {
                            SampleRectangle *rect_item = dynamic_cast<SampleRectangle*>( scene_item );
                
                
                            if (rect_item->get_time() < min_time)
                            {
                                scene()->removeItem(scene_item);
                            }
                
                            else 
                            {
                                scene_item->setPos( width() * ((double)(rect_item->get_time() - min_time) / (double)(max_time - min_time)), 0);
                            }
                            
                        }
                    }
                

                The code checks if the rectangle item is outside the screen (by determining whether its time is lower than the current displayed minimum time) and else, we update the position of the rectangle in the scene. However, printing a counter in the paint() method of the QRectItem, I still see the counter incrementing, indicating the the paint() method is called everytime the setPos() function is called. I'm using Qt5 by the way. Do you know why paint() is still called for every setPos()?

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

                @HappyVisualizer
                Whose paint() is being called? Presumably you mean that of a QGraphicsItem, like QGraphicsRectItem? So wouldn't you expect that to be called if you move the rectangle object? Something has to draw it at its new position, together with removing it from its old position....

                H 1 Reply Last reply
                0
                • JonBJ JonB

                  @HappyVisualizer
                  Whose paint() is being called? Presumably you mean that of a QGraphicsItem, like QGraphicsRectItem? So wouldn't you expect that to be called if you move the rectangle object? Something has to draw it at its new position, together with removing it from its old position....

                  H Offline
                  H Offline
                  HappyVisualizer
                  wrote on last edited by
                  #13

                  @JonB Yes, that makes a lot of sense to me. But then I may have to rethink whether using a QGraphicsView and painting 100,000 custom QGraphicsRectItems every 50 ms is feasible. What do you think, would this be possible, or should I use something else like do the drawing with OpenGL?

                  The reason I went for custom QGraphicsRectItems is their HoverEvent and the capability of displaying tooltips. With OpenGL, I have to implement this myself (which seems to be a bit harder, but not impossible).

                  JonBJ 1 Reply Last reply
                  0
                  • H HappyVisualizer

                    @JonB Yes, that makes a lot of sense to me. But then I may have to rethink whether using a QGraphicsView and painting 100,000 custom QGraphicsRectItems every 50 ms is feasible. What do you think, would this be possible, or should I use something else like do the drawing with OpenGL?

                    The reason I went for custom QGraphicsRectItems is their HoverEvent and the capability of displaying tooltips. With OpenGL, I have to implement this myself (which seems to be a bit harder, but not impossible).

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

                    @HappyVisualizer
                    Not my area I'm afraid. 100k per 50ms does sound like a lot to me. Don't forget that --- unless you explicitly tell scene/view to redraw each time you update a rectangle, which you should not do --- Qt will "buffer" all the updates. My understanding is that when it's that many it will probably end up redrawing the whole scene/view rather than each rectangle individually,

                    It would not surprise me if OpenGL is better at speed, but you will have to await a more knowledgeable expert in that area than I.

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

                      Do you really need to show that many times at the same time ?

                      One thing you should take into account is how much data makes sense to be shown. Take for example video games, they do not render absolutely everything in every frame because that fine detail that is supposed to be 1000m away does not make sense to render in full details because you can't see them anyway.

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

                      H 1 Reply Last reply
                      0
                      • SGaistS SGaist

                        Do you really need to show that many times at the same time ?

                        One thing you should take into account is how much data makes sense to be shown. Take for example video games, they do not render absolutely everything in every frame because that fine detail that is supposed to be 1000m away does not make sense to render in full details because you can't see them anyway.

                        H Offline
                        H Offline
                        HappyVisualizer
                        wrote on last edited by
                        #16

                        @SGaist It's a good question. Another possibility would be to aggregate data. The idea is that it is possible to zoom in and out over timeframes, so for instance when we look at a timespan of 1 minute, we need 60 * 1000 / 50 = 1200 objects to be repainted every 50 ms, which seems to be attainable. Then, when we go to a larger timespan (say 1 hour), it would be possible to aggregate and let every block consist of (for instance) 1 second of data instead of 50 ms of data. Then, to draw the whole scene, we need to draw 60 * 60 * 1000 / (20 * 50) = 3600 objects, which is a lot less than previously proposed. Would you support this strategy?

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

                          Yes, that's the idea. Clustering data for more meaningful representation.

                          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
                          • H Offline
                            H Offline
                            HappyVisualizer
                            wrote on last edited by
                            #18

                            @JonB, @SGaist It has been a while, but I have integrated the aggregation of data and it works like a charm. Thanks a lot guys!

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

                              Great !

                              Then please mark the thread as solved using the "Topic Tools" button or the three dotted menu beside the answer you deem correct so that other forum users may know a solution has Ben found :-)

                              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

                              • Login

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