本文介绍了QGraphicsScene子类忽略鼠标按下事件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有一个UI和QGraphicsScene子类GraphicsScene实现mousePressEvent(),但鼠标点击被忽略。
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()未被调用,因此不会发出clicked是否需要设置其他设置才能启用此功能?
GraphicsScene::mousePressEvent() is not called, and so does not emit signal clicked(). Is there something else I need to set to enable this?
更新:
void GraphicsView::mousePressEvent(QMouseEvent *event) {
emit clicked(event->pos());
}
它已连接到正确签名的插槽。
It's connected to a slot of the right signature.
推荐答案
mos关于函数签名是正确的。函数应该是:
mos was right about the function signature. The function should have been:
void GraphicsView::mousePressEvent(QGraphicsSceneMouseEvent *event) {
emit clicked(event->pos());
}
而不是
void GraphicsView::mousePressEvent(QMouseEvent *event) {
emit clicked(event->pos());
}
这篇关于QGraphicsScene子类忽略鼠标按下事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!