Solved How to Create QGraphicsItem(Lines, Rectangles, etc.) in QGraphicsScence by mouse?
-
@JonB Sorry, maybe I was misled you, I want a pen that I can draw anything I want, kind of doodle?Just one stroke when the mouse released the stroke become an object.
kind of this. -
@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 . -
@JonB ok, sorry I still have some question.
How can I do like I pressed mouse and hold, to draw a line until I released mouse, the line will become an object. -
@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. -
@JonB But if I create the QGraphicsLineItem at mousedReleasd, when I holding the mouse pressed, I can't see the line.
-
@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 want to override mouseMoveEvent to get my mouse position when my mouse is holding.
-
@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. -
@JonB You are right, sorry I am thinking too complicated