简体   繁体   中英

MouseMoveEvent in QGraphicsView

I need to get a move event in my main widget but the QGraphicsView catches the event, so I can't get it in my main widget. is there any way to turn this off, so i can catch the event like i would catch any mousemoveevent in my widget. Note: The problem is NOT that i have mousetracking disabled. I know about that and catching this event outside the graphicsview is working

Here are two possible solutions among dozens of them:

Ignore

From documentation:

You should call ignore() if the mouse event is not handled by your widget. A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.

// view.cpp

mouseMoveEvent(QMouseEvent *event){
event.ignore(); // propagated to parent
}

Double event

Try emitting a signal with mouse position from QGraphicsView, when a move event occurs, and catch it in main widget.

// view.cpp

mouseMoveEvent (QMouseEvent *event){
    emit mouseMoveSignal(event.pos());
    }


// mainwindow.cpp

mainWindow::mainWindow (QWidget * parent = 0){
    connect(view, SIGNAL(mouseMoveSignal(QPointF)), this, SLOT(mouseMoveSlot(QPointF)));
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM