Results 1 to 9 of 9

Thread: Not possible to send mouse events to QMainWindow??

  1. #1
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Not possible to send mouse events to QMainWindow??

    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!

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Not possible to send mouse events to QMainWindow??

    What reaction would you expect exactly from the window? Based on the fact that QMainWindow probably doesn't reimplement any mouse events, if you expect some fireworks and music then it likely will not happen unless you code it by reimplementing mouse events from the main window object.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Not possible to send mouse events to QMainWindow??

    well, background is the following:

    the Splitter within the QMainWindow is not implemented as a QSplitter, so I cannot switch off the opaque mode for handling when moving the splitter. The problem is, that when the user moves the splitter, all docked windows are updated at once and that causes a "chewing gum" effect. So I need to prevent the mouse events to be handled when the user moves the splitter (see the return true; in the eventFilter => event is handled and doesnt need to be handled by the parent any more). But when the user releases the mouse I have to send the mouse press event, ONE mouse move event and the mouse release event. so the splitter should be adjusted by the QMainWindow (at least that was my hope ) But it is not.

    Did I explain correctly? Or are there any more questions?

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Not possible to send mouse events to QMainWindow??

    I don't know what a "chewing gum" effect is. Anyway instead of faking events maybe you should just find a method that will resize the dock widget.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Not possible to send mouse events to QMainWindow??

    I call it "chewing gum" effect when the splitter lags behind the mouse movement, because several docking windows are busy to repaint themselves. And as for each single pixel all the docking windows are repainted, this slows down the whole procedure. I would like to switch this opaque moving mode off, but as I initially mentioned it is not possible for the QMainWindow splitter. Thus I thought I simulate the whole mouse press and dragging process as one single step.

    First I tried to somehow overwrite the resize event of the docking windows, but that's not working, somehow, then I tried to use the setUpdatesEnabled() function while moving, but that's not working for my case, because it seems that setUpdatesEnabled() is not thread-safe.

    So then I thought I solve it with resending the mouse events as one step.

    Nothing is working

  6. #6
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: Not possible to send mouse events to QMainWindow??

    Maybe you should focus on optimizing your dock widgets then
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  7. #7
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Not possible to send mouse events to QMainWindow??

    nope, because even if the dock widgets are empty, this lagging effect is there, because the QMainWindow mostly contains more than 5 dock widgets (and on this widget architecture I dont have influence on)

    I need to find a way to emulate the non-opaque moving mode.

    And I still hope anybody knows how I can resend these mouse events.

  8. #8
    Join Date
    Sep 2011
    Posts
    1,241
    Thanks
    3
    Thanked 127 Times in 126 Posts
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Not possible to send mouse events to QMainWindow??

    why not just use setOpaqueResize(false); on your splitter????

  9. #9
    Join Date
    Sep 2011
    Posts
    12
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Not possible to send mouse events to QMainWindow??

    because the splitter in a QMainWindow is not derived from QSplitter... => there is no such function, I need to fix it manually

Similar Threads

  1. send mouse button on Qt embedded
    By Thành Viên Mới in forum Qt for Embedded and Mobile
    Replies: 0
    Last Post: 25th May 2011, 10:18
  2. Replies: 0
    Last Post: 26th April 2011, 11:02
  3. Send a mouse right click into QGRaphicsScene
    By jano_alex_es in forum Newbie
    Replies: 2
    Last Post: 11th March 2010, 14:47
  4. Replies: 2
    Last Post: 1st August 2008, 16:58
  5. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.