0

I have my own subclass of QGraphicsScene lied behind QGrapnhicsView (I did not override it). My scene handles some mouse events (double and single click). But in the same time I want my view will be scrollable by cursor (QtGui.QGraphicsView.ScrollHandDrag). How could I block mouse event on view layer if it already caused scrolling, to not to bubble to the scene?

Alex G.P.
  • 9,609
  • 6
  • 46
  • 81

2 Answers2

0

You need to implement the mouseMoveEvent function from QGraphicsView and accept the event.

protected:
virtual void QGraphicsView::mouseMoveEvent(QMouseEvent * event)
{
    QPoint mouseLocation = event->pos();
    // Do stuff
    event->accept();
}

Accepting the mouse event prevents a parent class from handling that event.

This would prevent mouse move events from being propagated. Depending on what you want to do, you could also reimplement the mouseDoubleClickEvent, mousePressEvent, mouseReleasEvent, or wheelEvent functions. All of their function definitions are in the QGraphicsView documentation.

Cory Klein
  • 51,188
  • 43
  • 183
  • 243
  • It is not working in case of PySide. If I overrides any mouse-related methods and do not call parent's method explicitly scrolling functionality of QGraphicsView is not working. If I calling it explicitly and call `accept` method of event it is doing nothing - still propagated to scene. – Alex G.P. Aug 05 '13 at 06:23
0

As per the Qt documentation, you'll need to actually subclass the QGraphicsView and reimplement the mouseMoveEvent() method for your new subclass.

Reference: http://doc.qt.io/qt-5/qgraphicsview.html#dragMode-prop

EM-Creations
  • 4,195
  • 4
  • 40
  • 56