"Proper" way of handling events for a node-based editor / system.

  • Hi everyone,

    I am in the process of building a node-based system in Quick 2.0 like the one displayed below and I am facing the following problem.
    I want to be able to click in a node, e.g. Node B in Component A, drag the mouse and if I release on top of a node in Component B, create a connection.

    The problem is that the mouse released event is registered to the node where the click originated from and not the node where the mouse is currently over. I thought of using a DropArea for every node, having an invisible item on top of every node and dragging that item and dropping it on the node of the other component. When the drop happens, the invisible item should return to its original position.

    This is clearly not a good solution and it seems more like a hack. Would anyone have a suggestion of a more proper way of doing this??

    Thanks a lot!


    p.s: either a C++ / QQuickItem based suggestion or a straight QML one would be fine.

    !http://www.addictivelabs.com/files/qt_forums.png(Example figure)!

  • I'm sure there's a better way than this, but one hacky way is to get the mouse.x and mouse.y coordinates in the onReleased handler, then map those to the scene to determine which item was clicked. I'm sure there's a better way, though.


  • You should create a "slot" component that automatically exposes its position as mapped to the parent of its parent component, that will save you a lot with dealing with this in the clumsy way it is done in QML.

  • Thanks a lot to both of you for your answers!

    @chrisadams, am I right to assume that what you are suggesting to iterate through all nodes in the scene graph, get the bounding rect of the item and find if it contains the mouse???


  • Too bad there is no childAt() method in QML.

Log in to reply