Using Qt with DirectX?
Asked Answered
G

3

9

What exactly are my options? I have programs I need to write in OpenGL and DirectX, and I'd like to use Qt for OpenGL, and not have to re-implement half my program for the DirectX components of my task.

I've looked on Google and I have found references to people complaining about Direct3D being a dependency of Qt, and people talking about implementing QD3DWidget sub-classing QWidget in a similar fashion to QGLWidget, yet nobody talked about how to implement it or where any examples are.

I need help. I want to know if it is possible? What would I need to do to get it working? Has it been done before?

Gelb answered 29/10, 2009 at 2:22 Comment(1)
I know it's really old post, but when I wanted to do this, I searched just like you and didn't find much information. I therefore created this project to support Direct3D while using Qt: github.com/giladreich/QtDirect3D Hope that will help anyone who'll be looking for the same thing in the future.Fleischman
L
16

its pretty straightforward than I thought,

-> Create a QWidget
-> Override paintEngine() method, does nothing, just returns NULL
-> Assign HWND to widget->winId()

    #ifdef USE_QTGUI
        QApplication a(argc, argv);
        CD3DWidget wndw;    wndw.show();    wndw.resize(1280,960);
        hWnd = wndw.winId();
    #else
        hWnd = CreateAppWindow(name,300,300);
    #endif

       //CD3DWidget class contains only the following definitions
    CD3DWidget::CD3DWidget(QWidget * parent):QWidget(parent){      }
    QPaintEngine *CD3DWidget::paintEngine (){          return NULL;        }

Thanks,

CV

Landri answered 8/4, 2011 at 12:56 Comment(4)
Does this work in the latest QT? Both other answers say that the DirectX support was experimental and was removedGelb
Hello Tom, I tried this and works perfectly. I was able to run a DirectX QWidget and an OpenGL QWidget in the same QMainWindow.Landri
@Tom J Nowell: You don't need any support or integration in the toolkit to use Direct3D by itself, all you need is a native window handle and telling the toolkit to avoid clearing that window. The "experimental removed support" is as far as I understand it an accelerated rendering backend for Qt, which is a whole different thing.Benzoic
It seems to work for me but it hangs because I'm doing a while loop to render my stuff.Divisor
O
2

List of changes:

Qt 4.6 introduces many new features and improvements as well as bugfixes over the 4.5.x series.

......................

  • The experimental Direct3D paint engine has been removed. The reason for this is that Nokia focuses on OpenGL for desktop hardware accelerated rendering.

......................

Ortrude answered 29/10, 2009 at 12:8 Comment(0)
I
1

For all its worth, here is how to get Ogre3D's output to a Qt 4.5 window. Basically, you grab a rendering surface and you use it to render the output. This is a "Qt in D3D/OpenGL application approach".

Here are OpenGL examples with Qt 4.5 using OpenGL window.

If I understand it correctly, the Direct3D support is experimental and is only used for painting of windows.

Idleman answered 29/10, 2009 at 2:37 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.