Important: Please read the Qt Code of Conduct -

Using QT as a UI for game rendered with DirectX

  • Hi, I'm developing a game in a framework which uses DirectX for rendering and I'm coming to a stage where I want to implement a proper UI. Seeing how I have (some) experience with QT, it seemed like a natural fit.

    Without having delved too deep into the QT source code, would it be possible to render a QApplication (or anything using the QT framework for that matter) inside an application which is not QT, i.e. a game using DirectX? So for example, having a menu screen using QWidgets inside the same executable as the game itself.

    Any help would be much appreciated!

  • Lifetime Qt Champion

    Yes, you can have a Qt app that creates a DirectX context for the game part.
    However, Qt need the QApplication object and its event loop running so
    the other way around having a normal Windows message pump and then use Qt is
    more involved but not impossible.
    However, it should be quite possible to use Qt for menu etc but it wont render on top of
    a fullscreen directX surface as far as i know.

  • Moderators

    While it's certainly doable I would advise against it. If you already have a framework it's probably gonna be challenging to integrate its event loop with Qt's. Apart from that it's a question of what sort of integration you want. If you want Qt widgets on top of your rendering then you'd have to create Qt's widgets as a separate window on top of yours. This would probably complicate input and focus handling. If you want the widgets "inside" your DirectX scene or in a fullscreen mode you'd have to render the widgets into a pixmap, upload it as DirectX texture and render that in engine. This further complicates input handling, as you would basically have to "fake" Qt events, do coordinates translation, focus handling etc. It could also tank your performance, as the widgets are rendered on the CPU and uploading them as textures would be additional cost.

    All in all I think it's more trouble than it's worth. I would suggest to turn your eye into one of the libraries that are specifically targeted for exactly this kind of task, for example Dear ImGui. It has a lot smaller footprint than Qt, and integrates directly with your engine - i.e. it leverages the rendering and input handling that you already have.

Log in to reply