2

I'm trying to fiddle a bit with a Qt example regarding 2D Graphics.

Basically it is a small diagram editor. In the example, the author explains that the tracknodes() function is used to update the line's endpoints, when the user drags a connected node into a different position.

This actually does not happen. After looking at the code, I have the feeling it's because there is no event being called after moving the node QGraphicItem, in order to update the link's rendering.

I figured I have to find out where and how the QGraphicItem's movement is handled in order to send a wasDropped signal (or something like that) to a slot that re-renders the link. Does this make sense?

I'm pretty new to Qt/C++ in general, so I don't have a very clear idea on how to achieve this, does anyone have any pointers he/she could share?

Joum
  • 3,189
  • 3
  • 33
  • 64

1 Answers1

2

He seems to be using the QGraphicsItem::itemChange virtual function to call the tracknodes() function which draws the lines. ItemChange should be called every time a node is moved. It's called in other cases as well but he only uses it for tracking the movement of the QGraphicsItem.

thuga
  • 12,601
  • 42
  • 52
  • 1
    Actually I figured it out, there was a **ItemSendsGeometryChanges** flag missing in the _node_ cpp. But your answer is correct regarding what I actually asked. +1 – Joum May 31 '13 at 09:41
  • @Jorum Oh, sorry I forgot to mention that you need to set the `ItemSendsGeometryChanges` flag for the `QGraphicsItem` to get those notifications. I'm glad you caught that. – thuga May 31 '13 at 09:48