Reputation: 1094
I would like to select positions and items in a QGraphicsView
by mouse click and add items to the connected view at this position/item. Do I need to implement my own subclass of QGraphicsView
or is there a shorter solution, e.g. with signal/slot?
Upvotes: 0
Views: 425
Reputation: 4689
There are few ways to do it:
Reimplement mousePressEvent(QMouseEvent*)
(so, you need to implement subclass of QGraphicsView
),
Call installEventFilter(QObject *)
for QGraphicsView
and implement bool eventFilter(QObject *, QEvent *)
to catch all events (and process only QEvent::MouseButtonPress
inside this function). In this case you do not need to implement subclass of QGraphicsView
.
See also: Click event for QGraphicsView Qt and How to draw a point (on mouseclick) on a QGraphicsScene
Upvotes: 1