Question about migrating OpenGL from QGLWidget to QWindow
I'm migrating a project from Qt4 with OpenGL in QGLWidget to Qt5 with OpenGL in QWindow.
This "project":https://github.com/advancingu/Qt5OpenGL from Sean Harmer "Dev Days Talk":http://www.youtube.com/watch?v=GYa5DLV6ADQ has help me with with some doubts, but one thing is not clear, why nothing is draw if I disable the QTimer in Window.ccp constructor ? I'm guessing it's because paintGL() is a virtual function that works under the wood in QGLWidget, while in QWindow the equivalent is just a user defined function. Also I've notice that in QWindow, if I call paintGl() from the resizeGl() function, everything works, the triangle is draw without the timer (wich seems a waste of resources if we don't need animations). Can someone please clarify ?
The timer's job in Window.cpp is to call updateScene() at a rate of 16 times per second, so disabling it the scene is never drawn.
If you put paintGl() inside resizeGl(), the window will be drawn only when the window is resized, and also the scene won't get updated (so it won't change).
it's up to you what should happen to update and draw the scene.
QTimer is responsible for updating the scene, but I have nothing to update, so I'm disabling the timer. I just wanna draw what's inside the painGL(), that is the triangle, and it doenst get draw, unless I call paintGL() from resizeGL() . This behavior is different from QGLwidget, where I can draw anything from paintGL, without timers, and without having to call paintGL() from resizeGL(). This is what's puzzling me.
That's because paintGL() is a virtual function of QGLWidget, which is called by itself in certain situations (I guess).
QWindow doesn't have that virtual function, so it's up to you to call paintGL(). Maybe you should do inside showEvent().