PDA

View Full Version : opengl widget not able to embed in QGraphicsView



wagmare
14th December 2010, 05:57
Hi friends,

i tried to embed a QOpenGL widget to my QGraphicsView using QGraphicsProxyWidget .. i tried
adding the widget like this ..


QGraphicsProxyWidget *proxy = scene->addWidget(glWidget);

but it returns warning as

QPainter::begin: A paint device can only be painted by one painter at a time.

and it not showing the widget ...
when i replace the opengl widget with normal widget (QTextEdit) it renders it properly ..

my openGL paintGL() code is..


glClear(GL_COLOR_BUFFER_BIT|GL_DEPTH_BUFFER_BIT);
glMatrixMode(GL_PROJECTION);
glLoadIdentity ();
glOrtho(this->max_x,this->max_y,this->min_x,this->min_y,-1.0f,1.0f);
glPushMatrix();
glBindTexture(GL_TEXTURE_2D, texture);
glBegin (GL_TRIANGLE_STRIP);
....
....
glEnd ();
glPopMatrix();


please help me in solving this issue ... where it requires painter.save() function ..? or some other ..? in QGLWidget where i have to use Qt GL functions ..?

please help me ... thanks in advance ..

stampede
14th December 2010, 08:00
Well, in the QGraphicsScene::addWidget documentation its clearly stated:


Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller are not supported. Examples are QGLWidget and QAxWidget.


in QGLWidget where i have to use Qt GL functions ..?

What do you mean ? You dont know where to put your OpenGL code ? Again, have you read the docs ? http://doc.qt.nokia.com/stable/qglwidget.html

wagmare
14th December 2010, 08:10
in QGLWidget where i have to use Qt GL functions ..? sorry instead of using QPainter i had written Qt GL functions ...


Note that widgets with the Qt::WA_PaintOnScreen widget attribute set and widgets that wrap an external application or controller are not supported. Examples are QGLWidget and QAxWidget.

fine ... stampede ... can u tell me is there any other option to embed a OpenGL widget ..?
i got this reference http://www.qtcentre.org/threads/12309-Adding-QGLWidget-to-QGraphicsScene-problem

stampede
14th December 2010, 08:19
can u tell me is there any other option to embed a OpenGL widget ..?
Honestly, I dont know. Docs says that its not supported, but in the thread you've linked seems to be some kind of workaround for this. There is a code sample as well.
Just try the suggestions posted there and see how it goes.

wagmare
14th December 2010, 08:22
thanks for reply ... stampede ..

in that thread they are just adding that widget as seperate viewport not as QGraphicsItem ... ok i see is there any other way ..
and once again thanks for reply ..