Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct
Draw Qt widgets in DirectX/OpenGL context
Phoenox last edited by
I'm working on a little utility that will inject itself into a given game and display information in an overlay.
Now I'm wondering if I could use Qt to draw the items of this overlay.
To keep this topic manageable, I'm assuming I've already acquired the DirectX/OpenGL context of the game.
Given that, how can I draw a Qt widget into this context? Is there a way to set this context as "parent" for a widget?
I've already found solutions that suggested using an QOpenGlWidget and add the widgets to that. However, this does not work for me, since I cannot change the actual executable, and therefore not the way the drawing context is presented to the user. Furthermore, I'm looking for solutions that also would work with DirectX.
Assuming you have an OpenGL context and you can draw/create objects in it you would make that context current, then create a QOpenGLPaintDevice and use it to render() the widget into that. Please note that a widgets require a QApplication instance and a running Qt's event loop, so you would need to ensure you have that.
As for DirectX Qt doesn't have any direct support for it, but you could probably grab() a widget into a QPixmap, transfer the pixels to a DirectX texture and draw a quad with it.
If you feel adventurous you could also implement your own QPaintEngine, then subclass QPaintDevice to return that engine and use it like with the OpenGL version.