Results 1 to 1 of 1

Thread: QGraphicsView over existing QGLWidget

  1. #1
    Join Date
    Mar 2006
    Thanked 3 Times in 2 Posts
    Qt products
    Qt3 Qt4
    MacOS X Unix/X11 Windows

    Default QGraphicsView over existing QGLWidget

    I have an object which extends QGLWidgets and renders a 3d-scene.

    I need to add some buttons to the 3D view and some animation effects, like button opacity change.
    I found out that a simple way to do that would be render the 3D scene using a QGraphicsView as explained in this example

    The problem is that they don't use an already existing QGLWidget.
    They do their GL-rendering from QGraphicsView::drawBackground(...).

    Is there any way to render the QGraphicsScene scene using the QGLWidget rendering functions?
    I tried to call paintGL from the drawBackground function, but it is not working.
    This is the code

    Qt Code:
    1. ...
    2. //This is how the viewport is initialized
    3. QGraphicsView *oglGraphicsView = new QGraphicsView();
    4. oglGraphicsView->setViewport(new MyQGLWidget(QGLFormat(QGL::SampleBuffers)));
    5. oglGraphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    6. oglGraphicsView->setScene(new MyGraphicsScene());
    7. ...
    To copy to clipboard, switch view to plain text mode 

    Qt Code:
    1. // implementation of the drawBackground
    2. void MyGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
    3. {
    4. painter->beginNativePainting();
    6. glClearColor( 0.0, 0.0, 0.0, 1.0 );
    7. QList<QGraphicsView *> viewsList = views();
    8. if( viewsList.isEmpty() )
    9. return;
    10. MyQGLWidget *myGlViewport = static_cast<MyQGLWidget *>(viewsList[0]->viewport());
    11. // paint using MyQGLWidget rendering function
    12. myGlViewport ->paintGL();
    14. painter->endNativePainting();
    15. }
    To copy to clipboard, switch view to plain text mode 

    I know that the correct way to do it is to move the gl rendering in the drawbackground function, but to do that I will lose all high level rendering functions provided by QGlWidget.

    I would be very glad if you could give me some more hints.

    I'm using Qt 4.7


  2. The following 2 users say thank you to kalos80 for this useful post:

Similar Threads

  1. Replies: 1
    Last Post: 11th July 2012, 12:47
  2. Replies: 5
    Last Post: 9th January 2012, 21:22
  3. Replies: 1
    Last Post: 7th May 2010, 17:20
  4. Replies: 0
    Last Post: 17th August 2008, 17:31
  5. Mystic Problem (QGraphicsView + QGLWidget)
    By NoRulez in forum Qt Programming
    Replies: 2
    Last Post: 28th April 2008, 10:39


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.