hello,

I want to send mouse events to my class derived from QMainWindow. Therefore I installed an event filter which stores the corresponding events and then, if completed, sends to the main window. Basicly it is a mouse press, mouse move and mouse release event. I can see the events sent by sendEvent() in the eventFilter, but seem not to work within the main window (no reaction).

Here is the code:
Qt Code:
  1. bool MyMainWindow::eventFilter( QObject *pObj, QEvent *pEvent )
  2. {
  3. static bool bInternalSend = false;
  4. static QMouseEvent cStartEvent(QEvent::MouseButtonPress, QCursor::pos(), Qt::MouseButton::LeftButton, 0, 0 );
  5. static QMouseEvent cLastMoveEvent(QEvent::MouseMove, QCursor::pos(), Qt::MouseButton::LeftButton, 0, 0 );
  6.  
  7. if ( !bInternalSend )
  8. {
  9. if ( pEvent->type() == QEvent::MouseButtonPress )
  10. {
  11. QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
  12. if ( pMouseEvent )
  13. cStartEvent = *pMouseEvent;
  14.  
  15. this->StartRubberBand(); // show the rubber band at the current mouse position, depending on the mouse cursor shape
  16.  
  17. return true;
  18. }
  19. else if ( pEvent->type() == QEvent::MouseButtonRelease )
  20. {
  21. this->EndRubberBand(); // hide the rubber band
  22.  
  23. QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
  24.  
  25. if ( pMouseEvent )
  26. {
  27. bInternalSend = true;
  28. QApplication::sendEvent( this, &cStartEvent ); // send mouse press event
  29. bInternalSend = true;
  30. QApplication::sendEvent( this, &cLastMoveEvent ); // send last mouse move event
  31. }
  32. }
  33. else if ( pEvent->type() == QEvent::MouseMove )
  34. {
  35. QMouseEvent *pMouseEvent = dynamic_cast<QMouseEvent*>(pEvent);
  36. if ( pMouseEvent )
  37. cLastMoveEvent = *pMouseEvent;
  38.  
  39. this->MoveRubberBand(); // move the rubber band to the new mouse position
  40.  
  41. return true;
  42. }
  43. }
  44.  
  45. bInternalSend = false;
  46.  
  47. return QMainWindow::eventFilter( pObj, pEvent );
  48. }
To copy to clipboard, switch view to plain text mode 

Is it in general not possible to send mouse events to the main window? Or what is my fault?

Any help is appreciated!