Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. QGraphicsView over existing QGLWidget
QtWS25 Last Chance

QGraphicsView over existing QGLWidget

Scheduled Pinned Locked Moved General and Desktop
1 Posts 1 Posters 1.0k Views
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • K Offline
    K Offline
    kalos
    wrote on last edited by
    #1

    Hi,
    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
    http://doc.trolltech.com/qq/qq26-openglcanvas.html.

    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

    @...
    //This is how the viewport is initialized
    QGraphicsView *oglGraphicsView = new QGraphicsView();
    oglGraphicsView->setViewport(new MyQGLWidget(QGLFormat(QGL::SampleBuffers)));
    oglGraphicsView->setViewportUpdateMode(QGraphicsView::FullViewportUpdate);
    oglGraphicsView->setScene(new MyGraphicsScene());
    ...
    @

    @
    // implementation of the drawBackground
    void MyGraphicsScene::drawBackground(QPainter *painter, const QRectF &rect)
    {
    painter->beginNativePainting();

    glClearColor( 0.0, 0.0, 0.0, 1.0 );
    QList<QGraphicsView *> viewsList = views();
    if( viewsList.isEmpty() )
    return;
    MyQGLWidget *myGlViewport = static_cast<MyQGLWidget *>(viewsList[0]->viewport());
    // paint using MyQGLWidget rendering function
    myGlViewport ->paintGL();

    painter->endNativePainting();
    }
    @

    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

    Thanks,
    Calogero

    1 Reply Last reply
    0

    • Login

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Get Qt Extensions
    • Unsolved