Results 1 to 11 of 11

Thread: Adding QGLWidget to QGraphicsScene problem

  1. #1
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Adding QGLWidget to QGraphicsScene problem

    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

  2. #2
    Join Date
    Feb 2006
    Location
    Oslo, Norway
    Posts
    6,264
    Thanks
    36
    Thanked 1,519 Times in 1,389 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows Symbian S60 Maemo/MeeGo

    Default Re: Adding QGLWidget to QGraphicsScene problem

    Does it show anything if you show the plain QGLWidget without placing it on the scene?
    J-P Nurmi

  3. #3
    Join Date
    Jul 2007
    Posts
    90
    Thanks
    2
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Adding QGLWidget to QGraphicsScene problem

    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.

  4. #4
    Join Date
    Sep 2006
    Posts
    1
    Qt products
    Qt4
    Platforms
    Windows

    Default Re: Adding QGLWidget to QGraphicsScene problem

    I am having the same exact problem. Have you discovered a solution?

  5. #5
    Join Date
    Jan 2006
    Location
    Norway
    Posts
    124
    Thanked 38 Times in 30 Posts
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Adding QGLWidget to QGraphicsScene problem

    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.
    Bitto / Andreas Aardal Hanssen - andreas dot aardal dot hanssen at nokia
    Nokia Software Manager, Qt Development

  6. #6
    Join Date
    Feb 2008
    Posts
    51
    Thanks
    3
    Thanked 4 Times in 4 Posts
    Qt products
    Qt4
    Platforms
    MacOS X Unix/X11 Windows

    Default Re: Adding QGLWidget to QGraphicsScene problem

    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.

  7. #7
    Join Date
    Nov 2007
    Posts
    291
    Thanks
    85
    Thanked 1 Time in 1 Post

    Default Re: Adding QGLWidget to QGraphicsScene problem

    please provide some working code.

  8. #8
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding QGLWidget to QGraphicsScene problem

    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

  9. #9
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding QGLWidget to QGraphicsScene problem

    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
    Attached Files Attached Files

  10. #10
    Join Date
    Sep 2010
    Posts
    3
    Qt products
    Qt4
    Platforms
    Unix/X11

    Default Re: Adding QGLWidget to QGraphicsScene problem

    Now I have solved my problem. renderPixmap should not be called inside the paint funktion.

  11. #11
    Join Date
    Apr 2016
    Posts
    1
    Qt products
    Qt5
    Platforms
    Unix/X11

    Default Re: Adding QGLWidget to QGraphicsScene problem

    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.

Similar Threads

  1. QGLWidget Resize Problem
    By Sandip in forum Qt Programming
    Replies: 2
    Last Post: 28th February 2008, 06:47
  2. QGLWidget resize problem.
    By anderl in forum Qt Programming
    Replies: 2
    Last Post: 22nd January 2008, 08:57
  3. QPrinter on QGraphicsScene Border Problem
    By patrik08 in forum Qt Programming
    Replies: 1
    Last Post: 14th November 2007, 15:49
  4. why linking problem with QGLWidget???
    By Shuchi Agrawal in forum Newbie
    Replies: 17
    Last Post: 16th March 2007, 10:45
  5. Problem combining QWorkspace & QGLWidget
    By Nb2Qt in forum Qt Programming
    Replies: 1
    Last Post: 18th December 2006, 21:45

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.