PDA

View Full Version : Propagate mouse events 'physically' rather than 'logically'



sebastian.f
14th May 2009, 12:22
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!

wysota
14th May 2009, 13:25
Install an event filter on the popup. This way you'll be able to catch the event before it even reaches the overlay.

sebastian.f
14th May 2009, 15:33
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! :D

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

wysota
14th May 2009, 16:03
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.


void XX:mousePressEvent(QMouseEvent *me){
QCoreApplication::sendEvent(parentWidget(), *me);
}

sebastian.f
14th May 2009, 16:23
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 :)

wysota
14th May 2009, 20:46
Yes, that might be the reason :)