That's what I want to get. Clicking on a certain square (Rectangle) inside the scene with the mouse button, I do the "drag and drop" action and I need to draw ("stretch") the arrow from this square to the cursor while dragging. I created an arrow class, inheriting from QQuickItem and inside described updatePaintNode with something like:

QSGNode *Arrow::updatePaintNode(QSGNode *n, QQuickItem::UpdatePaintNodeData *) { QSGGeometryNode *node = static_cast<QSGGeometryNode *>(n); if (!node) node = new QSGGeometryNode(); _geometry.setLineWidth(2); _geometry.setDrawingMode(GL_LINE_STRIP); QSGGeometry::Point2D *v = _geometry.vertexDataAsPoint2D(); const QRectF rect = boundingRect(); QPointF itemStartPoint(_startX, _startY); //Переводим в глобальную систему координат QPointF sceneStartPoint = mapFromItem(nullptr, itemStartPoint); v[0].x = sceneStartPoint.x(); v[0].y = sceneStartPoint.y(); v[1].x = rect.left(); v[1].y = rect.top(); node->setGeometry(&_geometry); node->setMaterial(&_material); return node; } 

then set drag.target on the arrow object inside the scene. When dragging, the whole arrow is dragged, not its “tip,” the only way that came up with it is to do update (); inside onXChanged and onYChanged arrows:

 Arrow { id: defaultArrow; width: 1; height: 1; onXChanged: { update(); } onYChanged: { update(); } } 

It worked, but something seems somehow clumsy it. Is there a kosher way? Without a constant call update (); ? Maybe not at all on the basis of drag n drop, since in all the examples supplied on this topic we are talking about dragging objects entirely, but I need to start the arrow while dragging.

In general - how to drag the “part” of an object or change its appearance while dragging? For example, you may need to select objects using a "rectangular area", as it works when selecting several files, and now you only need to move the "corner" of this "rectangular area", and she herself has to change the shape, highlighting objects that fall into it.

  • one
    In my opinion, the arrow must have initial coordinates and a target node to which it is attached. The arrow will always be drawn from the origin of coordinates (its own) and end somewhere in the object (as you give it an ending), while its ending will depend on (x, y) the target object. Those. arrow knows nothing about drag'n'drop - ixSci
  • @ixSci What does "bind" to an object mean? Logically or a special Kuemelov term? I did something like this — dragging an invisible IT, and in it changing the end point of the arrow in the event on the move, but there’s essentially the same thing, you need to call update for the arrow to have an effect (but only more excess hassle with the extra object, so moved to move the arrow itself) - asianirish
  • Well in QML, you can set a property of type Item into which to place the object. During snapping, the arrow will snap to the (x, y) coordinates of this object. Or in general, do not fool your head, but immediately become attached to these coordinates - ixSci
  • @ixSci I move the Item (for visibility I made a Rectangle), inside which I added my own arrow. Same thing - without update () moves the whole arrow, not the tip - asianirish

0