[Really solved now!] Can not draw with OpenGL on QGLWidget
Can anybody comment this bug(?) ? Is it bug or my misunderstanding?
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).
Better yet, use the QGraphicsScene::drawBackground() and QGraphicsScene::drawForeground().
Not using QGlWidget and using QPainter::(begin/end)NativePainting instead helps me!
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
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."
Ok, it seems that begin and end NativePainting() and glScissor with proper coordinates helps me.
coule you tell us if your solution worked and share your code to others?
Yes, but later - in a few hours or tomorrow