我有一个UI和一个QGraphicsScene子类GraphicsScene,它实现了mousePressEvent(),但忽略了鼠标点击。
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()信号。我需要设置其他东西来启用它吗?
更新:
void GraphicsView::mousePressEvent(QMouseEvent *event) {
emit clicked(event->pos());
}
它连接到正确签名的插槽。
答案 0 :(得分:1)
void GraphicsView::mousePressEvent(QGraphicsSceneMouseEvent *event) {
emit clicked(event->pos());
}
而不是
void GraphicsView::mousePressEvent(QMouseEvent *event) {
emit clicked(event->pos());
}