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.