开发者

QGraphicsScene subclass is ignoring mouse press events

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 no开发者_运维技巧t 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.


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());
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜