Results 1 to 6 of 6

Thread: Pass mouseEvent to sibling widget?

  1. #1
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Question Pass mouseEvent to sibling widget?

    hi..

    i have parent widget "P" which has several child widgets which are not in a layout. i have just placed them to fixed positions by move()..

    child widget "A" has a irregular shape, by setting its background to a pixmap which has transparent sections.

    child widget "B" is button which is behind "A" (i.e the z-order), but "B" lies behind the transparent section of "A" so it is visible.

    1. now i want to click the "B" but i cannot because "A" is in front of it.
    2. If i use setMask() on "A", then i am able to click "B".
    3. But setMask() also disables the paintevent on transparent section of "A", and i have some childwidgets of "A" on the transparent section which do not show if i use setMask(). Therefore setMask() is not an option for me.
    4. I only need to pass mouseEvents to "B" so i ignore them in "A's" mouseEvents... but these
    ignored events goes to "P" (parent widget of "A"). I want to send the mouseevent to "B".

    so whats the best way to send the mouseevent from "A" to "B"?

    i am thinking that in the mouseEvents handlers of "P" i check wether the pos() of click comes in geometry of "B", then manually postEvent() a new mouseEvent to "B"...

    but this solution is not good i think... coz i forsee the mess of drag, please tell me what should i do in this situation?

    may be if someone knows how setMask() is able to send the event to "B".? i tried looking at the source but i was lost in the code...

  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: Pass mouseEvent to sibling widget?

    Two options:
    1. Reimplement mouse events for A and resend the event to B instead of ignoring it in A
    2. Install an event filter on A to forward events to B, there check if the event is in the transparent area and handle it there and then return true so that A doesn't get the event.
    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:

    nish (1st September 2009)

  4. #3
    Join Date
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Pass mouseEvent to sibling widget?

    thank you guruji for your reply..

    both the options you suggested are same as the some i was thinking of...
    i am thinking that in the mouseEvents handlers of "P" i check wether the pos() of click comes in geometry of "B", then manually postEvent() a new mouseEvent to "B"...
    so in all the three cases i have to postEvent() a new mouseEvent to "B"... ... so now as i got the confirmation of the guru.. i will go with it... ...

  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: Pass mouseEvent to sibling widget?

    sendEvent(), not postEvent().
    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
    Jun 2007
    Location
    India
    Posts
    1,042
    Thanks
    8
    Thanked 133 Times in 128 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Pass mouseEvent to sibling widget?

    postEvent()
    Adds the event event, with the object receiver as the receiver of the event, to an event queue and returns immediately.
    hmm... looking at the documentation.. i would prefer postevent so that it does not block anything... why you suggested sendEvent()? any specific reason that i may be ignoring?

  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: Pass mouseEvent to sibling widget?

    It won't block anything. I suggest sendEvent because you can reuse the same object you got from Qt instead of creating a copy of a specific QEvent subclass (which might be hard in itself). And someone might assume when the event to B is delivered, it will be handled, not that it will be handled later.
    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. QDockWidget inside another widget in the center?
    By Antebios in forum Qt Programming
    Replies: 1
    Last Post: 16th February 2010, 08:06
  2. Widget Focus
    By navi1084 in forum Qt Programming
    Replies: 6
    Last Post: 29th September 2008, 11:22
  3. pass mouse event information to another widget
    By Rooster in forum Qt Programming
    Replies: 5
    Last Post: 12th July 2008, 05:23
  4. How to Open & Close a Widget ?!!
    By Fatla in forum Qt Programming
    Replies: 6
    Last Post: 13th June 2008, 21:39
  5. Tricky problem with ARGB widget / UpdateLayeredWindow
    By nooky59 in forum Qt Programming
    Replies: 3
    Last Post: 21st February 2008, 11:35

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.