Draw ellipse in Qt5 (porting QPainter functionalities using QSG* classes)
-
Hi,
I did a project with Qt 4.8 and I used QDeclarativeIem and draw circles by using QPainter's drawEllipse method. Now, in Qt5, I really don't seem to find a way to do it. In the porting guide from qt4 to qt5 they say to use the QSG* classes, but I can't find a way to draw ellipses with any of them. I guess the two to look at are: http://qt-project.org/doc/qt-5.0/qtquick/qsgsimplerectnode.html and http://qt-project.org/doc/qt-5.0/qtquick/qsggeometry.html, but there is nothing...
Any idea? Thanks!
-
Hi, if you just want to port some "old" QPainter stuff you could use "QQuickPaintedItem":http://qt-project.org/doc/qt-5.0/qtquick/qquickpainteditem.html
If you want to create a custom scene graph item I think this example will help you getting started: https://qt-project.org/doc/qt-5.1/qtquick/scenegraph-customgeometry.html
-
Hi,
thanks for your fast answer!
I thought about doing that, but in the doc it says QSG* is much more performant, and since I'll be drawing probably more than a million of those items, I'd rather be as performant as possible.
What I understand from that example is that it is more of a opengl approach where you place the points and the lines are drawn between them, right? If so, it shouldn't be too hard to draw a circle... (I hope...)Thank you!
-
Well yes as far as I know the complete Qt scene graph is drawn with OpenGL, so the QSG files are just some interface classes for open GL in the end, to abstract open GL a little bit and reuse common stuff like line drawing etc.
But if you really want to draw 1000 or even millions of the same object you should consider doing a native open GL approach if you care about the best performance, that can also be done with QQuickItem (without using any of the QSG* classes), you just need to override the "paint" method, there are some examples somewhere I think.