Render QWidget in OpenGL

2.3k Views Asked by At

I have an OpenGL application and I would like to add a GUI to it.

My problem is that I want to keep my way of creating the window and my mainloop. In fact, I want to keep my application and just add some widgets to interact with the scene...

I know that we can use OpenGL as renderer by overloading QApplication but it creates a window and create another OpenGL context that i don't want... I know that I can use a QGLWidget to render OpenGL scene into it but it doesn't fit what I want too...

I searched on many forums without finding a solution. I want to know if it's possible and if yes, what is the way to achieved that ?

If it's not possible to do it, is there a way to do it ? It seems that CEGUI can do it but in my opinion it seems a bit young no ?

2

There are 2 best solutions below

5
On

My problem is that I want to keep my way of creating the window and my mainloop.

To use the Qt widget system you must use QApplication and the event system it spawn. You can't have two event loops battling between the same resources (windows, user input, signal reception and delivery).

In fact, I want to keep my application and just add some widgets to interact with the scene...

Then a beautiful Rolling Stones song applies to you: "You can't always get what you want…"

BTW? How are you creating the window right now? GLUT? Then deriving from QGLWidget and overriding its resizeGL, paintGL and timerEvent with a 0 delay timer to double as idle and the mouse*Event methods will give you quite the same behavior as GLUT has.

You might find that Qt's framework and event system is just what you need.

0
On

Did you try hello-gl example? It has a very good and clean code on OpenGL rendering and other basic operations (resize, loop, view). If you are having problem with GLUT, simply add glutInit(&argc,argv); right after int main().