Details
-
Bug
-
Resolution: Incomplete
-
P3: Somewhat important
-
4.5.0
-
None
Description
Using setHandlesChildEvents(true) on a widget, the widget events handler methods receive the events from the childs items. With an event filter installed on the widget, the filter do not show the same behavior as the event handler, the event received are only the ones from the widget.
The expected behavior would be to receive the events of the child in the parent filter.
Here is a test case for this problem:
#include <QtTest/QtTest>
#include <QGraphicsItem>
#include <QGraphicsView>
#include <QGraphicsWidget>
#include <QGraphicsScene>
class Filter : public QGraphicsWidget
{
public:
Filter():eventReceived(false){}
bool eventReceived;
protected:
bool sceneEventFilter ( QGraphicsItem * /watched/, QEvent * /event/ )
};
class Test : public QObject{
Q_OBJECT
private slots:
void testEventFilterWithHandlesChildEvents()
};
QTEST_MAIN(Test)
#include "test.moc"
And here is an example to visualize the problem, click on the green item, the event are shown in debug, click on the blue item, the events are not shown:
#include <QtGui>
class Filter : public QGraphicsWidget
{
protected:
bool sceneEventFilter ( QGraphicsItem * watched, QEvent * event )
};
int main(int argc, char **argv){
QApplication app(argc, argv);
QGraphicsView view;
QGraphicsScene scene;
view.setScene(&scene);
QGraphicsRectItem *parent = scene.addRect(0, 0, 50, 50, QPen(), Qt::green);
parent->setHandlesChildEvents(true);
Filter *filter = new Filter;
scene.addItem(filter);
parent->installSceneEventFilter(filter);
QGraphicsRectItem *child = scene.addRect(0, 25, 50, 50, QPen(), Qt::blue);
child->setParentItem(parent);
view.show();
return app.exec();
}