PDA

View Full Version : Graphics scene doesn't repaint properly



blooglet
14th April 2011, 22:17
I'm working with a graphics scene that can contain two types of QGraphicsItems: GraphicNodes and GraphicArcs. (Technically, GraphicNode inherits from QGraphicsRectItem because it made things easier for me but QGraphicsRectItems inherit from QGraphicsItem.) There are several types of GraphicNodes. Their only internal difference is their appearance.

Nodes can be attached to each other using arrows. (I have yet to implement arrow heads.) When I move a node and then try to drag it where it previously was, the arrow is no longer drawn correctly as shown in these screenshots and this blurry video: http://www.youtube.com/watch?v=AQ-bvwUJ9TY

6232

6233

Any thoughts on why this might happen? I didn't use QGraphicsItem's built-in "draggable item" support because I wanted to create a "ghost" preview during dragging. For the bounding rectangle of the arrows, I used the smallest possible rectangle that contains all begin/end points of the line pieces that form the arrow. As long as arrows stay out of the game, everything seems fine.

MarekR22
15th April 2011, 16:23
If I understand Arrows are implemented by you. It looks like that QGraphicsItem::boundingRect of this arrow is incorrect or you do not call QGraphicsItem::prepareGeometryChange before value of boundingRect is changed.

high_flyer
15th April 2011, 16:40
Any thoughts on why this might happen?
Looks like the algorithm used to draw the arrow is not error free.

Without code however, its hard to say.

blooglet
15th April 2011, 17:47
It looks like that QGraphicsItem::boundingRect of this arrow is incorrect or you do not call QGraphicsItem::prepareGeometryChange before value of boundingRect is changed.
Hmm... I didn't know that I had to call QGraphicsItem::prepareGeometryChange before changing the bounding rectangle. Quite stupid actually, because the doc for QGraphicsItem::boundingRect states that if you want to change the item's bounding rectangle, you must first call prepareGeometryChange(). Oops... :(

Once again, I'm amazed at how you guys can pinpoint the cause of my problems with the little information I provide. Thanks!

sean.reynolds
16th April 2011, 16:22
Are you able to post your code for this? I'm trying to do a similar thing with Arcs and Nodes. Are the nodes being logicially grouped in order as well?

Any help would be awesome.

Thanks

blooglet
16th April 2011, 16:48
Sorry... I can't post any code because the program I'm working on is a project for a Computer Science course. What do you mean with "logical grouping"?