Important: Please read the Qt Code of Conduct -

QGraphicsView with custom QGLWidget

  • Hello,

    I am trying to integrate this:
    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 )

    "This is the bare bones of the program.":
    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() {

    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": 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.
    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":

    Thank you

Log in to reply