Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Qt3D (C++) 2D Text (overlay) on top of Qt3DWindow



  • Hi,

    First I'm new to the Qt3D framework.
    I'm trying to put 2D text on top of a Qt3DWindow or the widget created from it. I tried multiple unsuccessful approaches and hope you can give me some clues as there is very few information and forum posts about that.

    For now I've tried to:

    • Use the QText2DEntity class. But it's actually creating a text in 3D space, which I don't want, I want a simple text on top of the 3D view.
    • Create a QLabel and raising it above the QWidget (using the raise() method) returned from the createWindowContainer(my3DWindow).
    • Using the paintEvent and QPainter.

    Now a thing that I didn't tried would be to create another viewport with an orthographic camera, and rendering a QText2DEntity. Is this a proper way to do that using this framework ? If so could you give me some pointers on which classes I should take a look at ?

    I would rather prefer to be able to draw widgets on top as I could use other components (ie: sliders, buttons).

    Thank you in advance !


  • Qt Champions 2017

    Your best bet is to use what comes from the Qt3D module. Other options are to embed a QML view inside the widget and use its elements to overlay over the window. The problem is that the Qt3D engine brings up a scene graph tree that is going to repaint the window, if you try to overlay something widget over it. It's a syncing issue, which ain't trivial to solve. On the other hand if you stick to QML, Qt3D integrates into the QML scene graph and it works properly. So in conclusion I suggest you use QML for that purpose, or stick with Qt3D's 2D primitives.



  • Okay thanks for the insights unfortunately I'm not very familiar with QML. Can you elaborate more on what Qt3D's 2D primitives are?


  • Qt Champions 2017

    That'd be QMesh with a properly oriented quad (i.e. QPlaneMesh) + a texture and QText2DEntity. I don't believe there's much else.

    PS. Another thing that came to mind is to use native widgets for the overlay, but that can be really costly if there are many.


Log in to reply