QGraphicsScene subclass is ignoring mouse press events

Deadly 提交于 2019-12-11 04:06:15

问题


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.


回答1:


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


来源:https://stackoverflow.com/questions/3549632/qgraphicsscene-subclass-is-ignoring-mouse-press-events

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!