PDA

View Full Version : Pass mouseEvent to sibling widget?



nish
1st September 2009, 08:10
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...:(

wysota
1st September 2009, 08:26
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.

nish
1st September 2009, 08:57
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... ...

wysota
1st September 2009, 09:02
sendEvent(), not postEvent().

nish
1st September 2009, 09:06
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?

wysota
1st September 2009, 13:00
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.