I want to know about how to draw a line between two nodes. .

1.4k Views Asked by At

simply i explain: first want to mouse press in graphicsscene and release the mouse. that point should be start point. then another plase i should press the mouse and release that will be end point then the line should be drawn. I can draw a line when mouse pressing and moving. but i want to know that abpve mentioned way. please some one help me. i am stuck in this .

1

There are 1 best solutions below

7
On

You can capture the location of mouse when mouse is pressed on graphics scene by handling mousePressEvent() of graphics scene, and using QGraphicsSceneMouseEvent's pos() method and store it.

Letter whey you detect second mouse click, use first point and second point to draw line.

From you question it looks you already know how to draw line so i will not put anything on that regards.

Something like following,

mousePressEvent( QGraphicsSceneMouseEvent * mouseEvent) {
    QPointF pos = mouseEvent->pos();
    if( mStartPoint.isNull() ) {
        mStartPoint = pos;
    } else {
        drawLine(mStartPoint, pos);
        mStartPoint = QPointF();
    }
}