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.