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?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Tom J Nowell
  • 9,588
  • 17
  • 63
  • 91
  • 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: https://github.com/giladreich/QtDirect3D Hope that will help anyone who'll be looking for the same thing in the future. –  Jan 18 '19 at 07:30

3 Answers3

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

Chenna V
  • 10,185
  • 11
  • 77
  • 104
  • Does this work in the latest QT? Both other answers say that the DirectX support was experimental and was removed – Tom J Nowell Apr 19 '11 at 11:00
  • Hello Tom, I tried this and works perfectly. I was able to run a DirectX QWidget and an OpenGL QWidget in the same QMainWindow. – Chenna V Apr 19 '11 at 16:07
  • @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. – Lars Viklund Sep 04 '11 at 14:19
  • It seems to work for me but it hangs because I'm doing a while loop to render my stuff. – Ryan Glenn Feb 20 '22 at 08:25
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.

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

TopSergey
  • 29
  • 1
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.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
Extrakun
  • 19,057
  • 21
  • 82
  • 129