View Full Version : How to use/embed a QGraphicsView into QML with touch events for pinch/pan?

9th July 2013, 14:21
Hi all,
I'm using Qt 4.8.2 on Windows7 (with touch screen) and XP (with mouse) for developing an application with graphical editor functionality for placing ICs on a board. The board is a simple image and the goal of that editor is to position the ICs an get their coordinates. That is well done with QGraphicsScene and QGraphicsView.

The Ui is made with QML because I want to use the ListView component to change several main pages horizontally which contains other custom QML components. On one page you should see the Editors view (exactly the QGraphicsView). Therefore I have "exported" the Editors view with qmlRegisterTyp() - now I can use it in my QML code. But the scene is managed in C++ and I get access to the instantiated Editor via QDeclarativeView->rootObject()->child() to set the scene of that Editor. Everything works fine.

The Editors QGraphicsView catches Touch events and implements a Pinch and Pan function.

The problem is that when I use it inside a QML main page, select an IC and move it horizontally the ListView is flicking to next main page. It seems the move/drag events are catched by the QML's declarative view before they passed trough to the Editor's QGraphicsView. I tried also to overwrite viewportEvent(), event() without success.

I know QML's declarative view is in reality also a QGraphicsView. What I make is to put another QGraphicsView into a QGraphicsView. I think to propagate the events between these views costs a lot of overhead.

But what kind of architecture I can use if I want to create my Ui with QML and the underlaying complex logic uses a QGraphicsScene?

Can I pass a QGraphicsScene to an predefined QML component? I think no.

Write the whole Ui in a QGraphicsView would become high complex and means QML should only be used for simple Uis. I think this is not the goal of QML.

Have anybody experience with embedding QGraphicsView in QML?

Thanks a lot...

18th July 2013, 14:23
see http://www.qtcentre.org/threads/55400-QML-Flickable-doesn-t-send-all-mouse-events-to-unterlaying-QGraphicsProxyWidget!?p=247634&highlight=#post247634