[Qt-interest] Events

Colin S. Miller no-spam-thank-you at csmiller.demon.co.uk
Tue May 4 21:17:02 CEST 2010


Malyushytsky, Alex wrote:
>>> 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
> 
> 
> 
Nokolay,

Just to clarify my code, the event filter can be in MyMainWindow; with Alex's hint you can
set *all* your Widgets (and any sub-widgets they may have) to be filtered by it, even if they
are in different windows that your app creates.

HTH,
Colin S. Miller






More information about the Qt-interest-old mailing list