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類中正確實現。 –