0
目前已经有线程了,但是我能找到的解决方案不起作用。 解决方案: 在我的MousePressEvent类的QGraphicsView派生类的末尾写QGraphicsView::MousePressEvent(event);
。 两者都不起作用。 QGraphicsItem类不接收鼠标事件。 这是我MousePressEvent在我的QGraphicsView类:如何在QGraphicsItem派生类中接收鼠标事件? Qt
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!";
}
任何想法,我已经忘记了吗?
你叫“QGraphicsView :: mousePressEvent(event);”在你的graphicsview类的mousePressEvent函数中?同时检查boundingRect()函数是否在您的graphicsitem类中正确实现。 –