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?
Asked
Active
Viewed 370 times
0
Ilya
- 4,583
- 4
- 26
- 51
user3561614
- 1,024
- 1
- 12
- 20
1 Answers
1
There are few ways to do it:
Reimplement
mousePressEvent(QMouseEvent*)(so, you need to implement subclass ofQGraphicsView),Call
installEventFilter(QObject *)forQGraphicsViewand implementbool eventFilter(QObject *, QEvent *)to catch all events (and process onlyQEvent::MouseButtonPressinside this function). In this case you do not need to implement subclass ofQGraphicsView.
See also: Click event for QGraphicsView Qt and How to draw a point (on mouseclick) on a QGraphicsScene