Integrating QGLWidget in QGraphicsScene
-
Hello,
After a long search I have found a possibility to put GUI-widgets on top of QGLWidgets on mac.
"here":http://labs.qt.nokia.com/2008/06/27/accelerate-your-widgets-with-opengl/According to the description:
All that’s needed is to set a QGLWidget as viewport on the graphics view, override QGraphicsScene::drawBackground() to do the OpenGL rendering, and add widgets and other graphics items to the graphics scene as usual.The code is more or less clear, except the part of including the QGLWidget. In the main it is done like this.
@
GraphicsView view;
view.setViewport(new QGLWidget(QGLFormat(QGL::SampleBuffers)));
@
I thought that it might be possible to integrate my own GLWidget, where i define the typical QGLWidget/OpenGL-Functions.I@
void initializeGL();
void paintGL();
void resizeGL(int width, int height);)
@
Somehow like this:
@
GraphicsView view;
view.setViewport(new MyGLWidget(QGLFormat(QGL::SampleBuffers)));
@
But it isnt working.The QGraphicsScene::drawBackground()-Function is not clear to me either. I think, that it somehow transforms the OpenGL-Code into a background where I can put on top of it GUI-Widegts. Somehow they are defining a painter-engine. Why do I need this. Dont know much about engines.
@
if (painter->paintEngine()->type() != QPaintEngine::OpenGL
&& painter->paintEngine()->type() != QPaintEngine::OpenGL2)
{
qWarning("OpenGLScene: drawBackground needs a QGLWidget to be set as viewport on the graphics view");
return;
}
@In the QGraphicsScene::drawBackground()-Function OpenGL-Code is used, but when I try to put my OpenGL code from paintGL there, I get errors, when I use swapBuffers or other QGLWidget-specific code. So it seems logical that the actual OpenGL-Code should be defined externally. I hope you could help me.
Thank you in advance... -
Hi there, lots of questions, huh?
I believe there is an error, because your QPaintEngine will never match your condition. Here I had problems because I have OpenGL2 and was comparing only OpenGL. Maybe if you replace && by ||.
@if (painter->paintEngine()->type() != QPaintEngine::OpenGL
|| painter->paintEngine()->type() != QPaintEngine::OpenGL2)@This path is difficult
[quote author="basil_fawlty" date="1314306305"]
I thought that it might be possible to integrate my own GLWidget, where i define the typical QGLWidget/OpenGL-Functions.I@
void initializeGL();
void paintGL();
void resizeGL(int width, int height);)
@
Somehow like this:
@
GraphicsView view;
view.setViewport(new MyGLWidget(QGLFormat(QGL::SampleBuffers)));
@
But it isnt working.
[/quote]Well, there is an example code you can use on the same "link":http://qt.gitorious.org/qt-labs/modelviewer you have pointed. It might be enlightening to you.
As the whys of this strategy, I honestly don't know.
I hope this helps,
Regards,
VitorAMJ