[Qt-interest] Events

OS Prog osprog at gmail.com
Sun May 2 15:53:18 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
>
> Hi Colin,

If I have many child objects with many QPushButtons each, do I have to
install the event filter for each of them?
And if I don't have an access to the widget (or don't have a rights to
change the code) how can deal then?
There should be other way (I hope).

Other case - if I emulate QMouseEvents, how can I pass them to the child
widgets (QWidget with QPushButtons) ?

Regards,
Nik
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.qt-project.org/pipermail/qt-interest-old/attachments/20100502/4de54046/attachment.html 


More information about the Qt-interest-old mailing list