QGraphicsView with custom QGLWidget



  • Hello,

    I am trying to integrate this:
    http://doc.qt.digia.com/qq/qq26-openglcanvas.html
    But I want to use a third party library that does the rendering.
    The class that currently renders is derived from QGLWidget.

    This is how it currently draws:

    @ void occView::paintEvent( QPaintEvent* e )
    {
    aView->Redraw();
    }
    @

    "This is the bare bones of the program.":http://www.datafilehost.com/d/1fbd2b78
    If anyone could help me with this I would greatly appreciate it

    Thank you



  • Added link to program



  • Well, you have to ship your code from third library to Qt's Graphics-View framework, an alternative is to override QGraphicsView's drawBackground() method and draw it.



  • Hello Jiangcaiyang,

    Thank you for replying.
    So if I override drawBackground()
    @
    drawBackground() {
    aView->Redraw();
    }
    @

    Is it as simple as this?
    I uploaded the project if you want to see how the drawing is done.



  • I am very sorry to tell you that I can't access your bare bone program.
    you mentioned that 3rd party library renders the widget in paintEvent method, I know, before doing any OpenGL command, they should call makeCurrent() first to ensure the OpenGL context is ready, and usually end with its method using doneCurrent(). and Qt's graphics-view framework is slightly different, as I mentioned above, drawBackground() method is called within QGraphicsView's paintEvent method, people who wants to do 2D overlays usually warp drawing OpenGL commands by called painter->beginNativePaining() and endNativePainting(), the "painter"variable is passed as an argument in drawBackground(). What if the third library uses QPainter again? I don't know, but you could have a try. If failed, please do let me know what the third library is. Hope to bring you useful information.



  • Hi Jiangcaiyang,

    I have tried what you said. No errors or warnings, but it still doesn't display.

    According to "this":http://doc.qt.digia.com/qq/qq26-openglcanvas.html If you do any painting using QPainter instead of using pure OpenGL commands, you will need to invoke save() and restore() on the painter.
    I did this as well.

    I have uploaded a basic example to a better file host, if you want to understand my problem better. http://www.mediafire.com/download/aaho6zeu6f4m5e7/Basic program.zip
    If I add "this->show();" in OpenGLScene, it shows the correct window in a seperate window, so there is nothing wrong with the code. I seems like it isn't adding it to the window.
    The third party library is "OpenCascade":http://www.opencascade.org/.

    Thank you


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.