2017-08-04 44 views
0

これについてのスレッドは既にありますが、私が見つけた解決策は機能しません。 ソリューション: QGraphicsView派生クラスのMousePressEventクラスの末尾にQGraphicsView::MousePressEvent(event);と書いてください。 どちらも動作しません。 QGraphicsItemクラスはマウスイベントを受け取りません。 これは私のMousePressEventは私のQGraphicsViewクラスである:QGraphicsItem派生クラスでマウスイベントを受け取る方法は? Qt

void Node::mousePressEvent(QGraphicsSceneMouseEvent *event){ 
    mousePressed = true; 
    qDebug() << "mouse trigered!"; 
} 

すべてのアイデア、私が忘れてしまった何か:

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がありますか?

+0

「QGraphicsView :: mousePressEvent(event);」と呼びますか?あなたのgraphicsviewクラスのmousePressEvent関数で?また、boundingRect()関数がgraphicsitemクラスで正しく実装されているかどうかを確認してください。 –

答えて

0

ANSWER は(QGraphicsView :: mouseMoveEventように(イベント)とを使用mouseMoveEventに)あなたがQGraphicsView派生クラスでオーバーライドごとのMouseEventの終わりに

QGraphicsView::mousePressEvent(event);/
QGraphicsView::mouseReleaseEvent(event);/
QGraphicsView::mouseMoveEvent(event); 
... 

を呼び出すことを忘れてはいけません。 それ以外の場合は、本当に奇妙なことが起こる可能性があります。 QGraphicsItem派生クラスでこれらのいくつかを使用していない場合でも、すべてのイベントで呼び出すことができます。

関連する問題