How to integrate QGraphicsView with QML.
-
My requirement is to draw some objects, like Line, Rect, and Circle.
I know the alternative way using Canvas, QPaintedItem etc.
But my thought is like, if we can integrate the QGraphicsView and QGraphicsScene with QML we can have very easy handling for graphic objects (with the help of QGraphicsLineItem......etc ). I tried to integrate this with QML by exposing the class which uses QGraphicView QGraphicScene and QGraphicsLineItem but something went wrong (I dont know whether its is possible or not). -
@Praveen-kk Hi! unfortunately it's no longer possible to integrate widgets into a QtQuick scene. It was possible with QtQuick 1.
-
Thank you Wieland..!
Any way can you tell me why they removed it from QtQuick 2. Am expecting your valuable suggestions on my issue. What is the better way to implement this kind of stuff in QML, also i may be required to save my object co-ordinates to back end database. Can you suggest me a good method to doing this.? -
QtQuick 1 was itself based on QGraphicsScene. This is why one could integrate QWidgets into a scene. The downside of this was the poor performance so QtQuick 2 was completely rewritten and has its own high-performance rendering stack which sits directly on top of OpenGL.
Your options are...
- Create lines, rectangles, circles etc as QtQuick items.
- Create a single QQuickPaintedItem to draw lines, rectangles, circles etc.
- Create a single QQuickItem to draw lines, rectangles, circles etc.
- Use a single QtQuick Canvas item to draw lines, rectangles, circles etc.
Option 1 is very easy to implement but performance might become an issue when you have a big number of elements. Option 2 uses QPainter as painting API and thus is easy to use but you'll have to manage all your objects by yourself and you also need to implement all user interaction by yourself. Option 3 has the best performance as you'll write your scene directly with OpenGL. Of course this is also very complicated. Option 4 makes no sense to me except if you want to avoid C++ and write your business logic in JavaScript.
-
@Wieland :
Create lines, rectangles, circles etc as QtQuick items.
Create a single QQuickPaintedItem to draw lines, rectangles, circles etc.
Create a single QQuickItem to draw lines, rectangles, circles etc.Dear Wieland ,
Can I get a sample for the above, Actually i am facing issue with line object. It will draw inside a rectangular area, so it is difficult to handle multiple objects.