Results 1 to 5 of 5

Thread: One QGLWidget that manage QGLWidget childs

  1. #1
    Join Date
    Dec 2012
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Maemo/MeeGo

    Default 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 :

    Qt Code:
    1. class ParentGLWidget : public QGLWidget
    2. {
    3. ...
    4. ParentGLWidget(QGLContext * context, QWidget *parent = 0) : QGLWidget(context, parent) {... }
    5. ...
    6. void initializeGL()
    7. {
    8. qglClearColor(qtPurple.dark());
    9. glEnable(GL_CULL_FACE);
    10. ...
    11. }
    12.  
    13. void paintGL()
    14. {
    15. glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
    16. }
    17.  
    18. void resizeGL(int width, int height)
    19. {
    20. glViewport((width - side) / 2, (height - side) / 2, side, side);
    21. glMatrixMode(GL_PROJECTION);
    22. glLoadIdentity();
    23. glOrthof(-0.5, +0.5, -0.5, +0.5, 4.0, 15.0);
    24. glMatrixMode(GL_MODELVIEW);
    25. }
    26. }
    To copy to clipboard, switch view to plain text mode 
    There are other “childs" GLWidget that should be drawn "inside" the parent widget context :
    Qt Code:
    1. class ChildGLWidget : public QGLWidget
    2. {
    3. ...
    4. ChildGLWidget(QGLContext * context, QWidget *parent = 0) : QGLWidget(context, parent) {... }
    5. ...
    6. void initializeGL()
    7. {
    8. // optional
    9. // at least, should not overwrite what have been done in the top level widget
    10. }
    11.  
    12. void paintGL()
    13. {
    14. glLoadIdentity();
    15. glTranslatef(0.0, 0.0, -10.0);
    16. glRotatef(xRot, 1.0, 0.0, 0.0);
    17. // draw some object in the gl world
    18. }
    19.  
    20. void resizeGL(int width, int height)
    21. {
    22. // optional
    23. // at least, should not overwrite what have been done in the top level widget
    24. }
    25. }
    To copy to clipboard, switch view to plain text mode 

    I would like to use them like this :
    Qt Code:
    1. QGLContext * context = new QGLContext(QGLFormat(QGL::SampleBuffers));
    2. ParentGLWidget * parent = new ParentGLWidget(context);
    3. ChildGLWidget * child_1 = new ChildGLWidget(context, parent);
    4. ChildGLWidget * child_2 = new ChildGLWidget(context, parent);
    To copy to clipboard, switch view to plain text mode 

    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.

  2. #2
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default 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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  3. #3
    Join Date
    Dec 2012
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Maemo/MeeGo

    Default 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.

  4. #4
    Join Date
    Jan 2006
    Location
    Warsaw, Poland
    Posts
    33,359
    Thanks
    3
    Thanked 5,015 Times in 4,792 Posts
    Qt products
    Qt3 Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Windows Android Maemo/MeeGo
    Wiki edits
    10

    Default Re: One QGLWidget that manage QGLWidget childs

    Quote Originally Posted by polch View Post
    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.

    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.

    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.
    Your biological and technological distinctiveness will be added to our own. Resistance is futile.

    Please ask Qt related questions on the forum and not using private messages or visitor messages.


  5. #5
    Join Date
    Dec 2012
    Posts
    3
    Qt products
    Qt4 Qt5 Qt/Embedded
    Platforms
    Unix/X11 Maemo/MeeGo

    Default Re: One QGLWidget that manage QGLWidget childs

    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.

Similar Threads

  1. Using more than one QGLWidget?
    By Paulpro in forum Qt Programming
    Replies: 0
    Last Post: 1st November 2010, 07:43
  2. QGLWidget and VBO
    By kaszewczyk in forum Newbie
    Replies: 1
    Last Post: 6th May 2010, 10:04
  3. Can not use QGLWidget.
    By Teuniz in forum Installation and Deployment
    Replies: 3
    Last Post: 25th September 2007, 00:27
  4. QGLWidget bug
    By Wizard in forum Qt Programming
    Replies: 11
    Last Post: 31st August 2007, 11:23
  5. qGLWidget
    By mickey in forum Newbie
    Replies: 8
    Last Post: 24th February 2006, 00:30

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.