Results 1 to 10 of 10

Thread: What element of Qlgwidget I'd pass to a class only to draw ?

  1. #1
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default What element of Qlgwidget I'd pass to a class only to draw ?

    I have a Qglwidget and I have a class that wants to draw itself in the 3dWorld.
    I can pass the 'this' reference to my_class_auto_draw_3d, but I dont want to use any other methods of the Qglwidget not related with opengl operations.
    That is to say, I have no interest to know or do nothing at the Qglwidget from my_class_auto_draw_3d.
    So, what object-element of Qglwidget can I use ?


    Thanks.

  2. #2
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    IMO I suggest this

    Qt Code:
    1. class My3DObject
    2. {
    3. ...
    4. public:
    5. virtual void draw ();
    6. };
    7.  
    8.  
    9. class MyGLWidget: public QGLWidget
    10. {
    11. ...
    12. public:
    13. void addObject (My3DObject *obj) { objects.push_back(obj);}
    14.  
    15. protected:
    16. void paintGL()
    17. {
    18. ....
    19.  
    20. Q_FOREACH (My3DObject* obj, objects)
    21. obj->draw();
    22. }
    23.  
    24. private:
    25. QVector<My3DObject*> objects;
    26. };
    To copy to clipboard, switch view to plain text mode 

    In this way each Object draw itself;
    A camel can go 14 days without drink,
    I can't!!!

  3. #3
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    Yes it can be a solution.
    In my case, I'd prefer the against proccess.
    And, in your opinion, what can be faster ?
    my_object.draw
    draw(my_object).
    (or it is the same ?)
    Thanks

  4. #4
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    Quote Originally Posted by tonnot View Post
    Yes it can be a solution.
    In my case, I'd prefer the against proccess.
    And, in your opinion, what can be faster ?
    my_object.draw
    draw(my_object).
    (or it is the same ?)
    Thanks
    IMO both have the same speed.
    the main difference is that

    • my_object.draw: each object knows how draw itself;
    • draw(my_object): the object that execute this has to know my_object data to draw it.

    in OO style I prefer the first one.
    A camel can go 14 days without drink,
    I can't!!!

  5. #5
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    So, we return to the first question.
    I have to pass the QGLwidget object to the objects constructor to let them can be drawed. Can I pass another "light" object ? In example QGLWidget.the_gl_engine ?
    (I dont see any tip at documentation )
    Thanks

  6. #6
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    wrong,

    the OpenGL painting must be done in paintGL method or in a method called inside it.
    A camel can go 14 days without drink,
    I can't!!!

  7. #7
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    Ok. But as you can create a Qpainter using QPainter painter(this); it could be appropiate to create a 'QGLPiainter' (If exists. ) .
    Do you think as me ?

  8. #8
    Join Date
    Jan 2006
    Location
    Napoli, Italy
    Posts
    621
    Thanks
    5
    Thanked 86 Times in 81 Posts
    Qt products
    Qt3 Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    The problem is that QGLPainter doesn't exist.
    A camel can go 14 days without drink,
    I can't!!!

  9. #9
    Join Date
    Sep 2010
    Posts
    654
    Thanks
    56
    Thanked 1 Time in 1 Post
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    Ja ja, Do you think that it can be a future feature ?
    Good weekend

  10. #10
    Join Date
    Aug 2011
    Location
    Seoul, Korea
    Posts
    46
    Thanks
    9
    Thanked 5 Times in 5 Posts
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: What element of Qlgwidget I'd pass to a class only to draw ?

    Quote Originally Posted by tonnot View Post
    Ja ja, Do you think that it can be a future feature ?
    Good weekend
    Sounds like you are trying to implement overpainting by using QGLWidget. You can override paintEvent() instead of paintGL(). There is a famouse tutorial about 2D drawing/3D rendering by using a single QGLWidget. Search "Qt overpainting".

    One thing I found a difficulty of using it is when you do QPainter within the paintEvent() you need to reset OpenGL machine states (i.e. no depth buffer). I think those should have been handled by QGLWidget internally. Other than that it works very well.

    Now since you can use normal QPainter in QGLWIdget, why would you need QGLPainter? =)

    Regards,
    Dong Back Kim

Similar Threads

  1. Replies: 2
    Last Post: 2nd July 2011, 01:02
  2. Replies: 3
    Last Post: 9th February 2011, 07:28
  3. Replies: 11
    Last Post: 14th March 2010, 22:00
  4. QRubberBand class to draw a line
    By vermarajeev in forum Qt Programming
    Replies: 9
    Last Post: 3rd April 2007, 06:53
  5. How to pass a QString to another class ?
    By probine in forum Qt Programming
    Replies: 9
    Last Post: 9th December 2006, 20:16

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.