Best practice drawing lines
-
For a QtQuick project I need a "rendering window" where I can draw custom 2D points and lines. And I have to be able to add those lines and object consisting of those lines (snapes) dynamically from C++.
I could use QPaintedItem which is easy but seems to be slow. Using QQuickwindow and QquickItem should be a lot faster. I understand how to define a derived version of those in C++. But all examples add one or more static graphic objects in the QML.
I need the graphic objects to be able to be added dynamically (runtime that is) to the scene.Any suggestions?
And are there any books about this ?Yours sincerely,
Edwin Martens -
@Edwin_martens said in Best practice drawing lines:
For a QtQuick project I need a "rendering window" where I can draw custom 2D points and lines. And I have to be able to add those lines and object consisting of those lines (snapes) dynamically from C++.
Have you looked at the Canvas item? It does not have a public C++ interface beyond what QQuickItem provides, but that may be sufficient.
I could use QPaintedItem which is easy but seems to be slow.
I'm presuming this is supposed to be QQuickPaintedItem, which forces work to be done in the GUI thread. That could be a problem. Have you profiled to determine what part is slow?
Using QQuickwindow and QquickItem should be a lot faster. I understand how to define a derived version of those in C++. But all examples add one or more static graphic objects in the QML.
I need the graphic objects to be able to be added dynamically (runtime that is) to the scene.The handler for this dynamic behavior can call QQuickItem::update() to schedule a redraw, or it can modify a property used in a display-related binding.
Any suggestions?
And are there any books about this ?There's a post pinned at the top of the QML and Quick section that discusses general performance issues using the scene graph. I think there are some blog posts about Qt Skinny (Quick with QML) that are performance oriented. I haven't see anything book length with this particular narrow focus.
-
I have done something like that using Qt Quick 3D, its blazing fast since it runs on gpu. I have used QQuick3DGeometry (c++), to define lines, it can be used also for points, then I have export it to qml. Then creating lines (or points) at runtime it is done like any qml Item, using createComponent(). If you want have a pick on my project. Qml line: https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/master/qml/qmlEntities/Line.qml and the c++ QQuick3DGeometry custom line https://bitbucket.org/joaodeusmorgado/techdrawstudio/src/master/entities/entity_line.h .
Also there was a video online not sure if from some qt blog post about drawing huge insane amount of points using Qt quick 3D but I cant find it right now. -
@GrecKo Thanks for the tips.
Initially I had a QList with c++ objects, but now for simplicity I am trying to avoid that. To manage the dynamic objects, each has a signal connection when they are created. Then when something happens, they receive signals and each object manage it self (turns visible, unvisible, gets deleted, ....). I think this approach it is much easier than creating filters and lists or repeaters.