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. What could be reasons for these leftovers on the scene?
QtWS25 Last Chance

What could be reasons for these leftovers on the scene?

Scheduled Pinned Locked Moved Unsolved General and Desktop
13 Posts 3 Posters 596 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
    Sano
    wrote on last edited by Sano
    #1

    Hello, I am working on an algorithm which moves rectangles between boxes. Therefore I am just using QGraphicsRectItems and whenever there is a rectangle moved somewhere else, I call setRect("moved Rectangle") for the specific QGraphicsRectItem so that this rectangle appears at another place. Sometimes there are moved more than one rectangle simultaneously and it seems that sometimes there are some leftovers of the rectangles before they have been moved. I am sorry that I can't post my code here but I am pretty sure that it's doing what it should do. The only thing are these leftovers. I posted two pictures of how that looks. I hope you can give me at least a hint what I could try.

    Leftover2.png Leftover1.png

    JonBJ 1 Reply Last reply
    0
    • S Sano

      Hello, I am working on an algorithm which moves rectangles between boxes. Therefore I am just using QGraphicsRectItems and whenever there is a rectangle moved somewhere else, I call setRect("moved Rectangle") for the specific QGraphicsRectItem so that this rectangle appears at another place. Sometimes there are moved more than one rectangle simultaneously and it seems that sometimes there are some leftovers of the rectangles before they have been moved. I am sorry that I can't post my code here but I am pretty sure that it's doing what it should do. The only thing are these leftovers. I posted two pictures of how that looks. I hope you can give me at least a hint what I could try.

      Leftover2.png Leftover1.png

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

      @Sano said in Why could be reasons for these leftovers on the scene?:

      whenever there is a rectangle moved somewhere else, I call setRect("moved Rectangle") for the specific QGraphicsRectItem so that this rectangle appears at another place

      I think of setRect() as an initial call, to establish the rectangle's size. Try setPos() instead for moving any QGraphicsItem, does that help?

      Otherwise are you using the in-built QGraphicsRectItem or did you derive from that yourself?

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

        Using setPos() breaks my code(the rectangles are all over the place). It seems that setPos() isn't working as I assumed.

        I have two central parts in my algorithm(the central part of the algorithm just works on QRect objects) where QRect is modified. It is always modified in the following ways:

        Let "a" be a QRect.

        a.moveTopLeft("some QPoint")
        or
        a.moveBottomRight("some QPoint")
        

        Of course when the algorithm changes the QRect object than you also have to change the QGraphicsRectItem object. Until now I have done this with setRect() by just passing the changed QRect object. I am not sure how I can achieve the same with setPos()

        If I change QRect "a" to QRect "b" by applying one of the two upper functions, how do I set the position for the QGRaphicsRectItem of "a" to get the "same" change for the scene object?

        And I am using the in-built QGraphicsRectItem.

        JonBJ 1 Reply Last reply
        0
        • S Sano

          Using setPos() breaks my code(the rectangles are all over the place). It seems that setPos() isn't working as I assumed.

          I have two central parts in my algorithm(the central part of the algorithm just works on QRect objects) where QRect is modified. It is always modified in the following ways:

          Let "a" be a QRect.

          a.moveTopLeft("some QPoint")
          or
          a.moveBottomRight("some QPoint")
          

          Of course when the algorithm changes the QRect object than you also have to change the QGraphicsRectItem object. Until now I have done this with setRect() by just passing the changed QRect object. I am not sure how I can achieve the same with setPos()

          If I change QRect "a" to QRect "b" by applying one of the two upper functions, how do I set the position for the QGRaphicsRectItem of "a" to get the "same" change for the scene object?

          And I am using the in-built QGraphicsRectItem.

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

          @Sano said in What could be reasons for these leftovers on the scene?:

          I am not sure how I can achieve the same with setPos()

          That only moves a rectangle. I didn't know you were changing sizes.

          I just meant to try it to see if still get artefacts, I don't know whether you can test to see if that is (somehow) the issue.

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

            I don't change the sizes of the QRect objects, the algorithm just moves them. Right now I am trying to rewrite the algorithm a bit but I somehow don't understand how setPos() works.

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

              Hi,

              Aren't you moving the QGraphicsRectItem objects ?

              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
                Sano
                wrote on last edited by Sano
                #7

                I am moving both. The algorithm just moves the QRect objects.

                I made a class called "Rectobject" which has a QRect member and an according QGraphicsRectItem member. The algorithm just processes the QRect object inside of this class and moves the QRect by using moveTopLeft() or moveBottomRight(). Whenever a "Rectobject" is processed a copy is sent to a queue which is processed by the scene in certain time intervals.

                In each of these time steps the sceneObject gets a "Rectobject" and with that we have the "updated" QRect "a" and also the QGraphicsRectItem "c" so that we can just call c->setRect(a) and so we move the according "Scene-rect". I don't know if I should have used setPos() but it worked absolutely fine with setRect() besides these leftovers.

                JonBJ 1 Reply Last reply
                0
                • S Sano

                  I am moving both. The algorithm just moves the QRect objects.

                  I made a class called "Rectobject" which has a QRect member and an according QGraphicsRectItem member. The algorithm just processes the QRect object inside of this class and moves the QRect by using moveTopLeft() or moveBottomRight(). Whenever a "Rectobject" is processed a copy is sent to a queue which is processed by the scene in certain time intervals.

                  In each of these time steps the sceneObject gets a "Rectobject" and with that we have the "updated" QRect "a" and also the QGraphicsRectItem "c" so that we can just call c->setRect(a) and so we move the according "Scene-rect". I don't know if I should have used setPos() but it worked absolutely fine with setRect() besides these leftovers.

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

                  @Sano said in What could be reasons for these leftovers on the scene?:

                  All my QRects are of the form QRect(0,0,x,y).

                  If that is the case and you alter x,y (and not the 0,0), you are not moving your rectangles, you are resizing them..... Your x,y are actually width,height.

                  Something is over-complex here. setPos() just sets the top-left x,y coordinates. There should no problem converting between setPos() & setRect(), providing you are changing x,y and not width,height.

                  Whether any of this affects your "trails" I do not know. Usually that happens by drawing outside the boundingRect(), but you don't seem to be doing that.

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

                    @JonB Sorry, I expressed the wrong thing. My QRect in the absolute beginning, when creating them, are all of the form QRect(0,0,x,y) and the only transformations done from there are moveTopLeft() and moveBottomRight().

                    Just to be sure: When lets say I have a QRect "a" and the according QGraphicsRectItem "b". Now I change "a" by doing

                    a.moveTopLeft(QPoint(50,50))
                    

                    When I want to change the Sceneobject than it would suffice to write:

                    b->setPos(a.topLeft())
                    

                    Am I right or is there something I don't understand.

                    JonBJ 1 Reply Last reply
                    0
                    • S Sano

                      @JonB Sorry, I expressed the wrong thing. My QRect in the absolute beginning, when creating them, are all of the form QRect(0,0,x,y) and the only transformations done from there are moveTopLeft() and moveBottomRight().

                      Just to be sure: When lets say I have a QRect "a" and the according QGraphicsRectItem "b". Now I change "a" by doing

                      a.moveTopLeft(QPoint(50,50))
                      

                      When I want to change the Sceneobject than it would suffice to write:

                      b->setPos(a.topLeft())
                      

                      Am I right or is there something I don't understand.

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

                      @Sano
                      So moveTopLeft() should be setPos(), and for moveBottomRight() you have to adjust for the width() & height() to pass to setPos(). setPos() sets the top-left.

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

                        Can you explain the data duplication ?
                        I fail to see why you have a structure with a QRect and a QGraphicsRectItem that you need to keep in sync at some while. QGraphicsRectItem already provides all the information you need.

                        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
                        • S Offline
                          S Offline
                          Sano
                          wrote on last edited by Sano
                          #12

                          @SGaist The data duplication could absolutely be unnecessary. I just thought somehow that I need both because when I change the QGraphicsRectItem inside the algorithm there would be no visualization because the algorithm isn't attached to some kind of timer. The visualization happens when the algorithm is over. It could absolutely be that the structure of this program is bad because there are so many things I don't know about Qt. First and foremost I need to somehow resolve the problem with these leftovers.

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

                            I added a "scene->update("Box where the Object was moved to")" to the code right after all the changes within this time step were done and the leftovers seem to be gone. After this change I didn't notice any leftovers so far.

                            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