PDA

View Full Version : Adding QGLWidget to QGraphicsScene problem



sanjayshelke
6th March 2008, 13:33
hi,
I have created small test application which adds QGLwidget to QGraphicsScene.

I have reimplement paintGL() method and drawing triangle by using openGL.

If i am adding this QGLWidget to QGraphicsScene by using addWidget() of Qt4.4.
Its not showing anything.


Can any one help me what is wrong in that.

regards,
~sanjay

jpn
6th March 2008, 13:42
Does it show anything if you show the plain QGLWidget without placing it on the scene?

sanjayshelke
6th March 2008, 14:00
Yes, it shows a triangle if i am not adding it to scene.
Even if i added it to the scene it make calls to the initializeGL(),resizeGL() and paintGL().
But it does nothing.

golgo32
9th May 2008, 02:37
I am having the same exact problem. Have you discovered a solution?

Bitto
14th May 2008, 09:14
Hi, guys. We don't directly support embedding of widgets that use Qt::WA_PaintOnScreen, such as QGLWidget, QX11EmbedContainer and QAxWidget. You can, however, set a QGLWidget as the viewport for QGraphicsView, try to embed the widget, and see what happens. If the QGLWidget uses QPainter to draw, it should work fine. But unfortunately it's not officially supported.

Sandip
14th May 2008, 16:31
Hi guys,

I have solved this problem with some tricks.
I know that it's not good to do these thinks but I don't find any right way.
Try to inherit your class from QGLWidget and QGraphicsItem and add the item to QGraphicsScene ( as item not widget).

You need to grab framebuffer and draw the image on item in it's paint method.

I tested my code on Windows, Linux and Mac OS and it works fine.

You should keep in mind that it works but not the right way to go on.

If you have any other question then feel free to ask me.

babu198649
3rd June 2008, 09:03
please provide some working code.

jburger
3rd September 2010, 14:38
Dear Sandip,

you have posted a request 2006 about adding a qglwidget to a qgraphicsscene.
I have the same problem.

I have tested your workaround but nothing is displayed.
Maybe you can send me a small example?

I have a paintgl and a paint function and inside the paint function
i have called grap picture and render picture but nothing works.

The item is added using sddItem of the graphicsscene.

Would be nice if you could help me.

best regards

jburger
6th September 2010, 08:21
Dear Sandip,

attached you can find my example code.

I create a QGraphicsItem and tried to grab an Image of the off screen QGLWidget
(My example you can find attached).
But neither grabFrameBuffer nor renderPixmap seems to work.
In both cases nothing is drawn.

In my small attached example a QMainWindow (class OpenGLSceneExample) contains the QGraphicsView which
contains the Scene. All Classes are contained in the openglsceneexample.* files.

If I add the QGLWidget (class CEasyGLWidget) as a child of the QGraphicsView the QGLWidget is drawn without problems.

If I draw a arc in a QGraphicsItem (class CEasyGraphicsItem)also this arc is drawn but
if I grab a picture of the QGLWidget nothing is drawn.

best regards,
Julika Burger

jburger
15th September 2010, 08:15
Now I have solved my problem. renderPixmap should not be called inside the paint funktion.

stravi
26th April 2016, 16:03
Hello guys,

I saw the attachment and I don't see the point of doing your painting in QGLWidget if you anyway repaint it in QGraphicsItem using QPainter. The idea of using OpenGL is to get a fast rendering environment. This way you will only increase your rendering time. Correct me somebody if I am wrong. And in this case I think that the best thing to do is to change you QGLWidget to QWidget and use QPainter instead of GL functions.