PDA

View Full Version : QGraphicsView stop drawing objects when a glwidget with GLVersion>3.1 set as viewport



raziel
11th December 2012, 17:46
When I create a QGLWidget with a custom GLFormat and set that widget as viewport of a qgraphicsview, if the glformat is higher than 3.1, the graphicsview stop drawing graphicsobjects or graphicsitems.

example( if I setVersion(3,1) the img pixmap is drawn, if I setVersion(3,3) the img pixmap doesn't appear in the scene):


QGLFormat glFormat;
glFormat.setVersion(3,1);
//glFormat.setVersion(3,3);
glFormat.setProfile(QGLFormat::CoreProfile);
glFormat.setOption(QGL::DoubleBuffer);
glFormat.setOption(QGL::DepthBuffer);
glFormat.setOption(QGL::Rgba);
QGLWidget* widget = new QGLWidget(glFormat);
QGraphicsView *graphicsView = new QGraphicsView();
QGraphicsScene *scene = new QGraphicsScene();
QGraphicsPixmapItem *img = new QGraphicsPixmapItem(QPixmap("btn-easy.png"));
img->setPos(100,100);
scene->addItem(img);
graphicsView->setViewport(widget);
graphicsView->setViewportUpdateMode(QGraphicsView::FullViewportU pdate);
graphicsView->setScene(scene);


Any idea if it can be fixed? Or something that I'm doing wrong?

I was using the http://doc.qt.digia.com/qq/qq26-openglcanvas.html openglcanvas approach to draw transparent items on top of a GLWidget. But since my custom GLWidget (it happens with default QGLWidget like on the example) requires OpenGL higher than 3.1 (actually should be 4.x), I cannot keep this approach.

Anyone know another efficient approach to draw transparent widgets on top of a QGLWidget or how to set a graphicview viewport with a qglwidget using glcontext 4.x?
QT5 handles the graphic pipeline differently from the QT4 , can QT5 be a solution? Did anyone successfully made an openGLCanvas on QT5?

Thanks in advance.

raziel
13th December 2012, 18:21
A co-worker solved the problem.
There is no need to setVersion on the glwidget glformat that will be set as viewport of a graphicsview, the qt itself use the current available maximum glversion, as long as QGLFormat::CoreProfile is set.

rodrigoshaller
17th September 2014, 20:24
A co-worker solved the problem.
There is no need to setVersion on the glwidget glformat that will be set as viewport of a graphicsview, the qt itself use the current available maximum glversion, as long as QGLFormat::CoreProfile is set.

Unfortunately, that isn't true if you're using OSX.
You need to set the OGL version (with QGLFormat) if you're need the 2.1> GLSL context, but if you do that, the QGraphicItems are not drawed.

This issue is killing me...
I didn't find a solution yet.

Regards,
Rodrigo Haller

raziel
18th September 2014, 01:35
Hi,
Sorry I can't help you out. When I had this issue I really tried everything I could and nothing worked out. The only thing that fixed the problem was not setting the ogl version, I was using windows but my co worker used osx and worked too. If I didn't type any glFormat.setVersion it would draw everything, and if i query the current version in a breakpoint or print would give my current graphic ogl version. Are you sure that your graphic card support that ogl version? (for instance if you have 2 graphic cards, your app might be using yout intel hd with ogl 2.1 support only) Have you tried new qt graphic classes ( i dunno how it turned out but when qt5 was released there was some new graphic classes i didnt explore, they might work better)?
good luck on solving this issue :)