已经有关于此的线程,但我能找到的解决方案不起作用。解决办法:写QGraphicsView::MousePressEvent(event);
在我的MousePressEvent类的QGraphicsView派生类的最后。两者都不起作用。QGraphicsItem 类不接收鼠标事件。这是我的 QGraphicsView 类中的 MousePressEvent:
void GraphWidget::mousePressEvent(QMouseEvent *event){
mousePressed = true;
if (event->button() == Qt::RightButton) // doesn't matter
{
rightMousePressed = true;
_panStartX = event->x();
_panStartY = event->y();
setCursor(Qt::ClosedHandCursor);
event->accept();
return;
}
// And I tried this: QGraphicsView::mousePressEvent(event);
}
这是我的 QGraphicsItem 类中的 MousePressEvent:
void Node::mousePressEvent(QGraphicsSceneMouseEvent *event){
mousePressed = true;
qDebug() << "mouse trigered!";
}
任何想法,我忘记了什么?