[Qt-interest] Events

Malyushytsky, Alex alex at wai.com
Tue May 4 00:07:29 CEST 2010


>>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).

void QObject::installEventFilter ( QObject * filterObj )
does not require you to change the code of existing widget.
The only thing you need is to get a pointer to QObject (QWidget) of each child.

You don't have to list children manually, check the following function
const QObjectList & QObject::children () const

together with QObject::isWidgetType () you can simply iterate through children and install event filter you need on them.

Hope this helps,
    Alex



From: qt-interest-bounces at trolltech.com [mailto:qt-interest-bounces at trolltech.com] On Behalf Of OS Prog
Sent: Sunday, May 02, 2010 6:53 AM
To: qt-interest at trolltech.com
Subject: Re: [Qt-interest] Events

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


---------------------------------------------------------------------------------------------------
Weidlinger Associates, Inc. made the following annotations.

“This message and any attachments are solely for the intended recipient and may contain confidential or privileged information. If you are not the intended recipient, any disclosure, copying, use, or distribution of the information included in this message and any attachments is prohibited. If you have received this communication in error, please notify us by reply e-mail and immediately and permanently delete this message and any attachments. Thank you.”

“Please consider our environment before printing this email.”




More information about the Qt-interest-old mailing list