Arya Sadeghi
Arya Sadeghi

Reputation: 500

How to use mouseEvent on QGraphicsView

I have a class that inherits QGraphicsView and I want to add mousePressEvent on this class.
How can I do that?

This is my function:

void mousePressEvent(QGraphicsSceneMouseEvent *event) {
    cards[0]->setPos(event->pos());
    scene->addItem(cards[0]);
}

Where cards[0] is a QGraphicsPixmapItem, but it doesn't work.

Upvotes: 1

Views: 848

Answers (1)

Fabio
Fabio

Reputation: 2602

I think you have the wrong parameter type in your mousePressEvent function.

In QGraphicsView you have to use mousePressEvent(QMouseEvent*) and not mousePressEvent(QGraphicsSceneMouseEvent*). The mousePressEvent(QGraphicsSceneMouseEvent*) is a method of QGraphicsScene, not of QGraphicsView.

Upvotes: 1

Related Questions