[英]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. 我需要在主窗口小部件中获取移动事件,但QGraphicsView会捕获该事件,因此无法在主窗口小部件中获取它。 is there any way to turn this off, so i can catch the event like i would catch any mousemoveevent in my widget.
有什么办法可以关闭它,所以我可以捕捉事件,就像捕捉小部件中的任何mousemoveevent一样。 Note: The problem is NOT that i have mousetracking disabled.
注意:问题不是我禁用了鼠标跟踪。 I know about that and catching this event outside the graphicsview is working
我知道这一点,并且在graphicsview之外捕获此事件正在工作
Here are two possible solutions among dozens of them: 以下是数十种可能的解决方案:
From documentation: 从文档:
You should call ignore() if the mouse event is not handled by your widget.
如果小部件未处理鼠标事件,则应调用ignore()。 A mouse event is propagated up the parent widget chain until a widget accepts it with accept(), or an event filter consumes it.
鼠标事件将在父窗口小部件链上传播,直到窗口小部件使用accept()接受它,或者事件过滤器将其消耗掉为止。
// view.cpp
mouseMoveEvent(QMouseEvent *event){
event.ignore(); // propagated to parent
}
Try emitting a signal with mouse position from QGraphicsView, when a move event occurs, and catch it in main widget. 发生移动事件时,尝试从QGraphicsView发出带有鼠标位置的信号,并将其捕获到主窗口小部件中。
// 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)));
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.