pyQt4 Events (like resizeEvent) are not trickling down to QGLWidget renderer inside QGraphicsView

166 Views Asked by At

I am trying to use the QGraphicsView/QGraphicsScene classes with a QGLWidget doing the bulk of rendering (I will need HW acceleration later down the road). My QGraphicsView(s) is tiled in a QGridLayout, itself inside a QDockWidget derived window. I cant seem to get events trickling down to the QGLWidget. I don't think its the layout architecture, because when I put the QGLWidget derived object directly in the QGridLayout 'tiles', events ARE passed to the OpenGL class. Its the QGraphicsView -> QGLWidget communication that's isn't working.

the code snippet in the QDocWidget that starts them up:

...
self.lightBoxes = []
for row in range ( numRows ):
    for col in range ( numCols ):
        #view = myImageView()        this wont see the GL renderer, why ?
        view = myGLView()
        self.gridLayout.addWidget (view, row, col )
        self.lightBoxes.append ( view )

and the QGLWidget and QGraphicsView derived classes are here. Again, events will make it to either object but not between them ( QGraphicsView and the QGLWidget )

class myGLView ( QtOpenGL.QGLWidget):
    def __init__(self, parent=None, GLFlags=0 ):
        print "MyGLView.__init__"
        QtOpenGL.QGLWidget.__init__( self, parent )


    def initializeGL(self):       
        print "myGLView.initializeGL"
        # ...

    def resizeGL (self, width=0, height=0):
        print "myGLView.resizeGL"

        glViewport(0, 0, width, height)
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity()
        gluPerspective(40.0, 1.0, 1.0, 30.0)
    #...

    def paintGL (self):
        print "myGLView.paintGL"
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)
        glLoadIdentity()
    # ....



#   ...resize Events wont trickle down from here...
class myImageView( QtGui.QGraphicsView ):    

def __init__(self, parent=None, origPixmap=None ):
    print "myImageView.__init__"
    QtGui.QGraphicsView.__init__( self, parent )
    QtCore.QMetaObject.connectSlotsByName(self)        

    self.GLRenderer = myGLView( self )        
    self.graphicsScene = QtGui.QGraphicsScene()        
    self.setViewport ( self.GLRenderer )
    self.setScene ( self.graphicsScene )        

def resizeEvent(self, event):
    print "myImageView.resizeEvent"        
    QtGui.QGraphicsView.resizeEvent( self, event )

My calling sequence must be screwy, I don't see any of the events (here the resizeEvent) making it to the pyOpenGL classes. I thought I followed the example code in the documentation. Any idea how I can it to work ?

thx

1

There are 1 best solutions below

0
On

Maybe you need to call myGLView with its parent (i.e. self)

view = myGLView(self)

that events are propagated.