One QGLWidget that manage QGLWidget childs
Hi.
I would like to know if the following use case is supported by QT.
I have one “Parent†QGLWidget :
Code:
{
...
...
void initializeGL()
{
qglClearColor(qtPurple.dark());
glEnable(GL_CULL_FACE);
...
}
void paintGL()
{
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
}
void resizeGL(int width, int height)
{
glViewport((width - side) / 2, (height - side) / 2, side, side);
glMatrixMode(GL_PROJECTION);
glLoadIdentity();
glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
glMatrixMode(GL_MODELVIEW);
}
}
There are other “childs" GLWidget that should be drawn "inside" the parent widget context :
Code:
{
...
...
void initializeGL()
{
// optional
// at least, should not overwrite what have been done in the top level widget
}
void paintGL()
{
glLoadIdentity();
glTranslatef(0.0, 0.0, -10.0);
glRotatef(xRot, 1.0, 0.0, 0.0);
// draw some object in the gl world
}
void resizeGL(int width, int height)
{
// optional
// at least, should not overwrite what have been done in the top level widget
}
}
I would like to use them like this :
Code:
ParentGLWidget * parent = new ParentGLWidget(context);
ChildGLWidget * child_1 = new ChildGLWidget(context, parent);
ChildGLWidget * child_2 = new ChildGLWidget(context, parent);
The childs could be managed (drawing, deletion, …) by the parent (like traditional widgets do), and I would be able to have some part of 3D rendering in "modules".
I haven’t been able to run such a use case.
Is there any design flaw in this use case ? Do you think there are others ways to do that ?
Thank for your help.
Re: One QGLWidget that manage QGLWidget childs
Traditional widgets are not managed by their parent in any way. Sharing GL contexts makes it possible to share textures and display lists.
Re: One QGLWidget that manage QGLWidget childs
Thank you for your reply.
I thought that the parent widget recursively triggered the display of its childs... So i thought that i would be possible to call the InitializeGL, paintGL, and resizeGL methods of the childs by a parent.
Actualy i have a class that contains a list of object with GL drawing methods that are called inside the paintGL method of an unique QGLWidget. I wondered if it was a good design.
Regards.
Paul.
Re: One QGLWidget that manage QGLWidget childs
Quote:
Originally Posted by
polch
I thought that the parent widget recursively triggered the display of its childs...
No. The parent paints itself on a given canvas and then each of its children paints itself on the same (or different) canvas. Then everything is assembled and rendered to the screen.
Quote:
So i thought that i would be possible to call the InitializeGL, paintGL, and resizeGL methods of the childs by a parent.
I don't think stacking GL widgets onto each other would do you any good.
Quote:
Actualy i have a class that contains a list of object with GL drawing methods that are called inside the paintGL method of an unique QGLWidget. I wondered if it was a good design.
Seems ok. Just call them from the GL widget's paintGL() implementation and you're done. No need for any extra widgets.
Re: One QGLWidget that manage QGLWidget childs
Quote:
Seems ok. Just call them from the GL widget's paintGL() implementation and you're done. No need for any extra widgets.
That what i actually do.
Thank you for the discussion.