Results 1 to 6 of 6

Thread: Propagate mouse events 'physically' rather than 'logically'

  1. #1
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Propagate mouse events 'physically' rather than 'logically'

    Hello,

    I have a bit of a problem with my Qt Widget.

    The way it works is I have a button (the base) that does some clever stuff depending on movements of the mouse in and around it.

    To instruct users on what to do there is an overlay (a subclassed QWidget) (significantly larger than the button) that is displayed as long as the button is held down.

    The base creates, shows & hides the overlay but because its so much larger, the overlay sets its parent to that of the main application (the bases parent).

    The problem now arises as I try and add a slight delay, so that the overlay lingers for a moment before it disappears; in this case, if the user releases the mouse and tries to click again, the overlay catches the mouse event locking the user out of the control until it vanishes.

    Of course Ignore() passes the mouse events to the parent, but because my overlay makes itself the sibling of the base control I want to handle the mouse event, this doesn't work.

    Could anyone tell me how to make my widget 'transparent' to mouse events so they are passed to the widget behind, instead of to the parent?

    Thanks!

  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: Propagate mouse events 'physically' rather than 'logically'

    Install an event filter on the popup. This way you'll be able to catch the event before it even reaches the overlay.
    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. The following user says thank you to wysota for this useful post:

    sebastian.f (14th May 2009)

  4. #3
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Propagate mouse events 'physically' rather than 'logically'

    Hi wysota,

    I've added an eventFilter function to my base and installed it as the event filter for the overlay.

    Its catching the events and passing them on successfully, Thank You!

    One more thing, is there a simple way to translate mouse events, as all my functions use the x()/y() functions where the coordinates are relative to the widget that created the event, so when I pass on the mouse events I need to translate them so my 'smart button' behaves properly.

    Its fairly straightforward but messy and I was just wondering if there was a small thing I mightv'e missed?

    Thanks again,

    Sebastian

  5. #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: Propagate mouse events 'physically' rather than 'logically'

    As far as I remember you can resend the event to another object and it will be "translated" for you, but I'm not sure of that.

    Qt Code:
    1. void XX:mousePressEvent(QMouseEvent *me){
    2. QCoreApplication::sendEvent(parentWidget(), *me);
    3. }
    To copy to clipboard, switch view to plain text mode 
    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.


  6. #5
    Join Date
    Apr 2009
    Posts
    19
    Thanks
    4
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Propagate mouse events 'physically' rather than 'logically'

    Hi wysota,

    I've just tried sendEvent() and it didn't translate it, however that might be because im telling my object to send the event to itself.

    Thanks

  7. #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: Propagate mouse events 'physically' rather than 'logically'

    Yes, that might be the reason
    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.


Similar Threads

  1. Mouse events in QGraphicsPixmapItem and QGraphicsTextItem
    By manojmka in forum Qt Programming
    Replies: 3
    Last Post: 8th August 2008, 11:38
  2. QGraphicsView Mouse Events
    By tomf in forum Qt Programming
    Replies: 5
    Last Post: 29th July 2008, 15:03
  3. Replies: 9
    Last Post: 22nd June 2008, 22:26
  4. mouse moving don't produce mouse events
    By coralbird in forum Qt Programming
    Replies: 1
    Last Post: 13th September 2006, 06:13
  5. QStackerWidget and mouse events
    By high_flyer in forum Qt Programming
    Replies: 3
    Last Post: 25th April 2006, 19:25

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.