PDA

View Full Version : How to deal the mouse event both in the child widget and parent widget?



tszzp
12th January 2010, 07:37
I need deal the mouse event both in the child widget and parent widget, deal the mouse event in the parent widget first, then deal the mouse event in the child widget. Now I use the installEventFilter to monitor the child widget's event in the parent widget, but I find I can't receive the QEvent::MouseButtonPress and QEvent::MouseButtonRelease event in the parent widget's function eventFilter, but I can receive the child widget's paint, polish and other events. How to solve it? thanks.

high_flyer
12th January 2010, 08:55
you are probably returning true after dealing with the event in your eventFilter method.
You have to return true if you want the event to be processed on higher levels,

tszzp
12th January 2010, 10:53
Sorry, I can't understand you. Can you explain it in detail? thanks.

high_flyer
12th January 2010, 13:04
show your eventFilter() method, then I can show you in the code.

tszzp
13th January 2010, 02:15
I install the eventfilter in the statement: pWidget->installEventFilter(this); in the QDirectManipulationWrapPanel class.
Now I can receive the pWidget's Paint, Polish and other event in the QDirectManipulationWrapPanel::eventFilter function,
but I can't receive the QEvent::MouseButtonPress in the QDirectManipulationWrapPanel::eventFilter function. thanks.
bool QDirectManipulationWrapPanel::eventFilter ( QObject * watched, QEvent * event )
{

if (watched == pWidget)
{
if (event->type() == QEvent::MouseButtonPress)
{
mousePressEvent((QMouseEvent*)event);
}
}
return QWidget::eventFilter(watched, event);
}

high_flyer
13th January 2010, 10:50
Please use the code tags when posting code.

Your eventFilter() is not doing enything with the event.
How do you know that MouseButtonPress is not being trapped?

tszzp
14th January 2010, 08:28
I already resolve the problem, thank you. I need receive the child's child event, but I only monitor the child widget's event. Now I can receive the MouseButtonPress event.

xlttap
14th January 2010, 08:47
Add the parent's parent widget's mouse event in the end of the mouse event in the parent widget.
e.g. QParentWidget inhrets QWidget, in the mouse event of QParentWidget wrote following:
void QParentWidget::mousePressEvent(QMouseEvent *event)
{
// do anything....
QWidget::mousePressEvent(event);
}

void QChildWidget::mousePressEvent(QMouseEvent *event)
{
// do anything....
}