When re-implementing any mouse event function in a QGraphicsPixmapItem such as mousePressEvent
, mouseReleaseEvent
, mouseMoveEvent
, the graphics item uses pixel-perfect collision. For example, for the mousePressEvent
to be triggered, the mouse must be exactly on top of a visible pixel in the pixmap when clicked.
On the other hand, I want the collision to be a generalized box based on the pixmap's width and height: [0, 0, width, height]
.
How can this be accomplished?
(Some sample code cause people seem to like that):
class MyGraphicsItem: public QGraphicsPixmapItem {
public:
MyGraphicsItem(): QGraphicsPixmapItem() {}
protected:
void mousePressEvent(QGraphicsSceneMouseEvent* event) {
// do stuff. Will be called when clicked exactly on the image
QGraphicsPixmapItem::mousePressEvent(event);
}
}