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 with custom QGLWidget
Qt 6.11 is out! See what's new in the release blog

QGraphicsView with custom QGLWidget

Scheduled Pinned Locked Moved General and Desktop
6 Posts 2 Posters 2.2k Views 1 Watching
  • 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.
  • D Offline
    D Offline
    daniel132
    wrote on last edited by
    #1

    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

    1 Reply Last reply
    0
    • D Offline
      D Offline
      daniel132
      wrote on last edited by
      #2

      Added link to program

      1 Reply Last reply
      0
      • J Offline
        J Offline
        jiangcaiyang
        wrote on last edited by
        #3

        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.

        1 Reply Last reply
        0
        • D Offline
          D Offline
          daniel132
          wrote on last edited by
          #4

          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.

          1 Reply Last reply
          0
          • J Offline
            J Offline
            jiangcaiyang
            wrote on last edited by
            #5

            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.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              daniel132
              wrote on last edited by
              #6

              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

              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