Rendering QGraphicsScene into QML scene texture
-
Hi,
The general concept is that the scene is rendered in a QImage that is then converted to a texture to be used by the node.
See the renderScene and updatePaintNode functions.
Hope it helps
-
@SGaist thanks for the answer.
I'm asking because I have already implemented a complex scene with many elements (font glyphs, lines), let's say similar to linear chart with a few series of data.
Porting it to QML canvas seems to be heavy job and using javascript to manage logic rather has performance impact whether I have logic already written in C++.
Because managing those elements requires operating on flat pane coordinates, using other techniques mentioned in above post (QML native elements or reimplementing QQuickItem or QQuicaPainted item) seems to be not my case.But please correct me if I'm wrong.
-
I'm not sure I'm following you. From what you described, following the technique of the DeclarativeChart class will likely be the simple road since you have everything already working with a QGraphicsScene.
-
Then,, AFAIK, without reimplementing everything, the QQuickItem way will likely be the simplest.
-
You don't render the QImage to a texture, your render your scene on a QImage and then you make a texture of it. Qt already supports creating texture from QImage.
-
I tested it with different options what brought me to following:
UsingQQuickPaintedItemand painting scene content (or its part) in overloadedpaint()method gives the same effects like rendering toQImageand using it as a texture.
But when QQuickPaintedItem has set:setRenderTarget(QQuickPaintedItem::FramebufferObject);to drawing directly using GL paint engine- it is much faster (2-3 times)
so:void MyQuickPaintedItem::paint(QPainter* painter) { graphicsScene->render(painter, boundingRect(), boundingRect()); }Does its job well
-
Great !
Thanks for the feedback.