How to Create QGraphicsItem(Lines, Rectangles, etc.) in QGraphicsScence by mouse?
-
@darrenleeleelee1
If you want to create those "freehand" letter drawings as aGraphicsItem
you would have to add it as aQGraphicsPathItem
composed from a multi-itemQPainterPath
. Unless you are prepared to do it as aQGraphicsPixmapItem
, and lose the ability to manipulate the points.It probably doesn't matter which of
QGraphicsScence
orQGraphicsView
to catch the mouse event, so long as it works. I did refer you to the DiagramScene example which seems to use the scene's mouse event. -
@darrenleeleelee1
You might get some clues from https://doc.qt.io/qt-5/qtwidgets-widgets-scribble-example.html in combination with https://forum.qt.io/topic/94586/draw-line-on-mouse-click & https://forum.qt.io/topic/94622/need-help-with-qgraphicsitem-painter . -
@darrenleeleelee1
I don't know what to say, it's just code you need to write. Note where the mouse goes down, note where the mouse is released and at that stage create aQGraphicsLineItem
or whatever between those two points. -
@darrenleeleelee1 said in How to Create QGraphicsItem(Lines, Rectangles, etc.) in QGraphicsScence by mouse?:
But if I create the QGraphicsLineItem at mousedReleasd, when I holding the mouse pressed
How can you get mouse released event if you hold mouse button pressed? Can you please explain better?
-
@jsulm I am thinking if I can change the existing QGraphicsLineItem to keep update to where my mouse position, and the start position is the moused click position.But I don't know how to adjust existing QGraphicsLineItem.
-
@darrenleeleelee1 said in How to Create QGraphicsItem(Lines, Rectangles, etc.) in QGraphicsScence by mouse?:
But I don't know how to adjust existing QGraphicsLineItem.
Again, I don't know what to say. You have
QGraphicsLineItem::setLine()
. I don't see the problems you see.