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. [Really solved now!] Can not draw with OpenGL on QGLWidget
Forum Updated to NodeBB v4.3 + New Features

[Really solved now!] Can not draw with OpenGL on QGLWidget

Scheduled Pinned Locked Moved General and Desktop
11 Posts 5 Posters 7.8k 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.
  • B Offline
    B Offline
    baysmith
    wrote on last edited by
    #2

    When a QGLWidget is set as the viewport of a QGraphicsView, the painting occurs through the QGraphicsView and does not call QGLWidget::paintGL(). Use the QGraphicsView::drawBackground() and QGraphicsView::drawForeground() methods instead. (Note: OpenGL calls will need to be between QPainter::beginNativePainting ()/endNativePainting() calls).

    Nokia Certified Qt Specialist.

    1 Reply Last reply
    0
    • F Offline
      F Offline
      Franzk
      wrote on last edited by
      #3

      Better yet, use the QGraphicsScene::drawBackground() and QGraphicsScene::drawForeground().

      "Horse sense is the thing a horse has which keeps it from betting on people." -- W.C. Fields

      http://www.catb.org/~esr/faqs/smart-questions.html

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

        Thanks!
        Not using QGlWidget and using QPainter::(begin/end)NativePainting instead helps me!

        1 Reply Last reply
        0
        • D Offline
          D Offline
          DimanNe
          wrote on last edited by
          #5

          No, I can not draw neither from drawBackground nor from drawForeground because I know nothing about second QLWidget (I even do not know about its existance).

          Suppose I develop a library, with class TFancyTabWidget, which can display arbitrary pages and
          1)I want to use some 2d effects (shadows, blur and so on) => I should use QGraphics* stuff,
          2)I want to various FAST animations => I should use QGLWidget as viewport. I tried use simple QWidget but in this case animations became not animations and 1-2 frames :)
          3)As TFancyTabWidget developer I know NOTHING about pages, that I will display - it may be simple QWidget, or QWidget with QGLWidget as child, or QGLWidget...
          3)As TFancyTabWidget developer I also want that me class works fine.

          PS I updated sources for better understanding of structure and relations, please use attachment New_TwoGlWidgetsBug.tar.gz from "http://bugreports.qt.nokia.com/browse/QTBUG-18813":http://bugreports.qt.nokia.com/browse/QTBUG-18813

          1 Reply Last reply
          0
          • B Offline
            B Offline
            baysmith
            wrote on last edited by
            #6

            QGraphicsScene::addWidget() creates a QGraphicsProxyWidget which does not support widgets which draw directly onto the screen, like a QGLWidget. (See http://doc.qt.nokia.com/4.7/qgraphicsproxywidget.html#setWidget)

            You'll have to restrict the arbitrary pages to QGraphicsItems and QWidgets. Since the QGraphicsView is setting the viewport to a QGLWidget, derivatives of QGraphicsItems and QWidgets can use OpenGL in their painting functions if properly surrounded by QPainter::beginNativePainting ()/endNativePainting() calls.

            Note the warning in the "QGraphicsProxyWidget documentation":http://doc.qt.nokia.com/4.7/qgraphicsproxywidget.html#details which states that it "is provided for convenience when bridging QWidgets and QGraphicsItems, it should not be used for high-performance scenarios."

            Nokia Certified Qt Specialist.

            1 Reply Last reply
            0
            • D Offline
              D Offline
              DimanNe
              wrote on last edited by
              #7

              Ok, it seems that begin and end NativePainting() and glScissor with proper coordinates helps me.

              1 Reply Last reply
              0
              • H Offline
                H Offline
                hornuda
                wrote on last edited by
                #8

                Hello DimanNe,
                coule you tell us if your solution worked and share your code to others?

                1 Reply Last reply
                0
                • S Offline
                  S Offline
                  Sam
                  wrote on last edited by
                  #9

                  -deleted-

                  1 Reply Last reply
                  0
                  • D Offline
                    D Offline
                    DimanNe
                    wrote on last edited by
                    #10

                    Yes, but later - in a few hours or tomorrow

                    1 Reply Last reply
                    0
                    • D Offline
                      D Offline
                      DimanNe
                      wrote on last edited by
                      #11

                      See
                      https://gitorious.org/eventmanager/eventmanager/blobs/master/src/libs/utils/TFancyTabWidget.cpp
                      and
                      https://gitorious.org/eventmanager/eventmanager/blobs/master/src/libs/utils/TFancyTabWidgetContent.cpp

                      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