[solved] QML Flickable doesn't send all mouse events to unterlaying QGraphicsProxyWidget!
-
Hi all,
Im using Qt 4.8.2 / QtQuick 1.1 on Windows with VS2010.
I want to "show" a complex QGraphicsScene in QML. The goal of the scene is to be like a visual editor where you can select items (e.g. labels) and position them free inside its parent item (circuit board).
When I "expose" the scene/view through QGraphicsProxyWidget and instantiate it in a QML file and loads it via QDeclarativeView it works - I can select/move the items and the implemented C++ function for pinch/pan gestures are working (transfoming the views matrix).
But when I use a QML horizontal flickable (flick from left to right and backwards) and puts the "exposed" scene/view on one of flickables pages then the flickable catches all mouse move events. I can select a scene's item to move it up/down but move it to left/right the flickable begins to flick to next page.
I tried all... overloading QGraphicsScene/View/QGraphicsProxyWidget::mouseMoveEvent(), keyPressEvent(), ... with the result:
mouseMoveEvent() is called few times before the flickable starts.
keyPressEvent() never called.It seems the flickable doesn't propagate the events to underlaying widgets "exposed" from C++.
But when you implement a simple image viewer with pinch/pan gestures in QML and you are "pinch" on the image the viewer catches the events and works - the flickable doesn't start to flick to next page.
I don't know if that is a flickable bug or I understand something wrong. But I think it's typically to implement the programs logical layer, here a complex scene, in C++ and expose it to QML for displaying it.
Catching all events in QML an sends it explicitly to the "exposed" class needs to much overhead - I can't believe that this is the right solution.
Any ideas?
Thanks a lot. -
I found a solution:
To stop flicking when use a pinch gesture, mouse events inside a child component of a flick page you have to set the flickable's property "interactive" to false. Then the pinch/mouse events are propagated to underlaying childs.
To get key input you have to set Flickable's focus to true.
Note: In my case I use a QGraphicsProxyWidget to embed a custom QGraphicsView/Scene into QML. The propagated events from QML to that widget seems to finished at QGraphicsProxyWidget's handler. From that point it's your task to deliver events further.
To set focus of Flickable and change it's property interactive I emit my defined signals interactiveFlick(bool) and focusFlick(bool) from inside QGraphicsProxyWidget::sceneEvent().