cmannett85
cmannett85

Reputation: 22376

Update a QGraphicsItem whilst a drag is occuring

I'm creating a QGraphicsView-derived widget which, amongst other things, needs to create connections between items in it - a little like a control flow graph. But I am having trouble implementing a method to 'draw' the connections

I've tried two approaches:

  1. Creating a QGraphicsLineItem-derived object when the source object's mouseMoveEvent(..) is fired, and updating it with each subsequent move. The line is drawn and updated successfully, but ultimately this does not work because it seems that moving the mouse 'locks' the event loop into only handling mouse move events, so the other object's hoverEnterEvent(..)/hoverMoveEvent(..)/etc. methods are not called (these are required to finalise the connection).
  2. Creating a QDrag instance in the mouseMoveEvent(..) to create the connection between two objects allows the two objects to form a connection once dropped, but ultimately this does not work because the QDrag::exec() call provides no means for other objects to be notified of the mouse moving - so the drawn connection cannot be updated.

I really need a mix of the two: in a perfect world the QDrag::exec() call would allow other some sort of notification of a mouse move, so I could update the object that represents the connection. Does anybody have a suggestion?

Similar to this question.

Upvotes: 2

Views: 863

Answers (1)

Eric Hulser
Eric Hulser

Reputation: 4022

I have an open source widget that does this, it is for PyQt, but it may help for what you are looking for.

You can find it in the projexui framework at http://dev.projexsoftware.com/projects/projexui

The code you are looking for is specifically the XNodeWidget class found in projexui/widgets/xnodewidget

Ultimately, I am using the mouse press event to start a connection via the scene and am ignoring the event (based on some sort of trigger - control press or hotspot zone etc.)

Hope that helps!

(an example of what it looks like is the table view on the Orbiter app - http://www.projexsoftware.com/software/orbiter)

Upvotes: 1

Related Questions