Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
drawText in QQuickItem
I'm writing a QQuickItem to display a ruler.
So I have several lines and some text.
I have no problem to draw the lines but I don't see a good way to draw my text next to it.
As it seems that there is no textGeometry I would like to instantiate qml-Textelements from c++.
In what class do I find the qml-textelements?
AFAIK it won't be easy to display text in QQuickItem instead did you consider using QQuickPaintedItem ? It uses QPainter with which you can use one of the drawText functions to draw text.
QQuickPaintedItem will use a texture to display my text.
Lets say I rescale the ruler with an animation. On every render I will have to create a new texture and I think the performance will be quite bad.
Yes it does but you wont need to do it manually as the paint() will do it internally. I don't know how GPU intensive your application is but I had been using it for some of my projects which included animations and it worked fine without any noticeable performance drop.
Ok, so I tried to use QQuickPaintedItem now.
My idea was to mix painting with paint() and direct drawing with updatePaintNode().
Unfortunately paint gets never called when I implement the updatePaintNode() function.
Is there a workaround?
If using QQuickPaintedItem it's better to use paint() rather than updatePaintNode().
AFAIK there's no way to use QPainter in updatePaintNode().
@p3c0 i tried using QQuickPaintedItem and use QPainter to draw text, however seems like there's a problem when rendering the text, it appears to be pixelated or blurred in iOS (retina deisplay) devices while on Android, everything is perfect. Read somewhere that antialiasing isn't working on QQuickPaintedItem. Do you know any workaround on this? TIA.
@p3c0 Thank you for the quick reply.
I actually encountered such bug report already however I can't find the qsgpainternode.cpp file in my Qt folder. Did i miss some patch or update to download? TIA.
Based on the documentation, QtDeclarative has already been deprecated in favor of the two new classes: Qt Quick and Qt QML. QQuickPaintedItem can be use as convenient way to port QDeclarativeItem-based classes that use the QPainter API.
I've been searching on the internet how to render text on QSG nodes but to no avail. I'm still stuck into this problem. :(