views:

78

answers:

1

I have a UI and a QGraphicsScene subclass GraphicsScene that implements mousePressEvent(), however mouse clicks are being ignored.

ui->setupUi(this);
scene = new GraphicsScene(this);
scene->addPixmap(QPixmap::fromImage(someImage));
ui->graphicsView->setScene(scene);
connect(scene, SIGNAL(clicked(QPoint)), this, SLOT(someSlot(QPoint)));

GraphicsScene::mousePressEvent() is not called, and so does not emit signal clicked(). Is there something else I need to set to enable this?

UPDATE:

void GraphicsView::mousePressEvent(QMouseEvent *event) {
        emit clicked(event->pos());
}

It's connected to a slot of the right signature.

A: 

mos was right about the function signature. The function should have been:

void GraphicsView::mousePressEvent(QGraphicsSceneMouseEvent *event) {
        emit clicked(event->pos());
}

rather than

void GraphicsView::mousePressEvent(QMouseEvent *event) {
        emit clicked(event->pos());
}
CakeMaster
Glad you found the problem!
rubenvb
Yep, thanks very much for your help earlier.
CakeMaster