PDA

View Full Version : Is there any easy way to get all child control's mouse click event??



yxmaomao
4th August 2008, 02:55
Guess there is a widget[named as A] which includes some child widgets
and these child widgets maybe include some others child widgets, and so on

now I want to A to get all the mouse click event , no matter which subcontrol use click on.

Does anyone know an easy way to implement this ?

spirit
4th August 2008, 07:03
you can use

void QObject::installEventFilter ( QObject * filterObj )
read more in Assistant, it has an exapmle.

yxmaomao
4th August 2008, 07:44
yes, I got it, should be like this:

QList<QWidget*> widgets = qFindChildren<QWidget*>(this);
foreach(QWidget *widget, widgets)
widget->installEventFilter(this);
installEventFilter(this);
then we can install event filter for all children, that's perfect!
good luck to every one who want to get this.