[Qt-interest] Events
Colin S. Miller
no-spam-thank-you at csmiller.demon.co.uk
Sat May 1 22:21:53 CEST 2010
OS Prog wrote:
> Hi,
>
> I'm trying to disable the mouse events to QWidget and its child widgets
> and to replace them with my custom event.
> I have event() function in my parent class and I'm receiving my custom
> events there. After decoding them I'm trying to prepare QMouseEvend and
> send it to the widgets, but their child widget doesn't receive it... I'm
> kind of lost with the events.
>
> I'll try to post some code later.
>
> Regards,
> Nikolay
Nokolay,
IIRC,
Events are send to the widget that has focus (for keyboard), or the mouse is over (for mouse events).
If widget-class is not interested in an QEvent in MyWidget::Event() then it should call
Event() in its parent class. If the event makes it upto QWidget::Event() (ie no-one is interested in it),
then the event is then sent to the parent (containing) widget of MyWidget.
Therefore, you can't block a child from receiving an event this way.
However, by using the following code, a widget can monitor (and block) any
events sent to another widget.
Here, the containing widget is monitoring its child, but they
don't have to be related.
MyParentWidget::MyParentWidget(...)
{
QWidget *myChild = ....;
myChild->installEventFilter(this);
.....
}
MyParentWidget::eventFilter(QObject *o, QEvent*e)
{
cout << "Object " << o << " received event " << e->type() << ", blocking." << endl;
return TRUE; // TRUE blocks the event, FALSE allows 'o' to see the event.
}
HTH,
Colin S. Miller
More information about the Qt-interest-old
mailing list