I'd like to override my QGraphicsView's behavior when the QGraphicsScene inside it isn't in a certain state. I want to do this to prevent graphic items that have the ItemIsSelectable flag enabled from being selected.

This is what I tried.

Qt Code:
  1. void MyCustomGraphicsViewImplementation::mousePressEvent(QMouseEvent *event) {
  2. MyCustomGraphicsSceneImplementation* theScene = dynamic_cast<MyCustomGraphicsSceneImplementation*>(this->scene());
  3.  
  4. if (theScene) {
  5. /* Is our scene in Select mode? Then we'll follow the default implementation
  6.   * of mousePressEvent. */
  7. if (theScene->getSceneMode() == MyCustomGraphicsSceneImplementation::Select) {
  8. QGraphicsView::mousePressEvent(event);
  9. }
  10. /* If we're in another scene mode, just send out the mouse event to the graphics scene without selecting anything */
  11. else {
  12. QMouseEvent gsEvent(QEvent::MouseButtonPress, event->pos(), Qt::LeftButton, Qt::LeftButton, Qt::NoModifier);
  13. QApplication::sendEvent(theScene, &gsEvent);
  14. }
  15. }
  16. }
To copy to clipboard, switch view to plain text mode 

This code compiles, but the mouse press event doesn't register correctly with the scene. How can I redirect the mouse event to the graphics scene without executing QGraphicsView::mousePressEvent?