Hello!
I need to create a slightly complex item for a graphics scene. In particular, imagine a circle that is flying across the screen. The circle has a position, of course, and there is an arrow attached to it, which indicates its velocity. I would like to drag the circle with the mouse to change its position, and I would like to be able to drag the tip of the arrow in order to change the velocity. What is the best strategy to create this item?
I could for example just subclass QGraphicsEllipseItem which gives me the circle, and hack the rest into it by drawing the error in the paint() method, and checking in the mouse event methods if the mouse is on the arrow or on the circle. This way seems a bit hack and I'm sure there is a cleaner way.
I could also subclass QGraphicsEllipseItem and QGraphicsLineItem and add the circle and the arrow as separate items to the scene and connect the arrow to the circle using a parent child relationship. I don't now how I would go about keeping things on one object in the end, one object that has a position and a velocity. Do I somehow find the parent of the arrow and write the velocity into the parent?
Then there are also item groups, but I don't see any advantage of using them at the moment.
Can anyone give pointers please?
Thanks
Cruz
Bookmarks