[PyQt] PyQT and OpenGL

Tim De Graeve timdgcb at gmail.com
Sat Nov 3 11:51:40 GMT 2007


Hello,

I don't know if this is the right mailing list to post my question on 
because I don't know if my problem is QT or OpenGL related.
Anyway I am taking my first steps with PyQT and OpenGL and wrote the 
following code based on the C++ code from the book OpenGL Superbible and 
the gears.py sample delivered with PyQT:

#!/usr/bin/env python

import sys
from qt import *
from qtgl import *
from OpenGL.GL import *

class TestGLWidget(QGLWidget):
    def __init__(self,parent=None,name=None):
        QGLWidget.__init__(self,parent,name)
       
    def paintGL(self):
        glClear(GL_COLOR_BUFFER_BIT)
        glColor3f(1.0, 0.0, 0.0)
        glRectf(-25.0, 25.0, 25.0, 25.0)
        glFlush()
       
    def resizeGL(self, w, h):
        if (h == 0):
            h = 1
           
        glViewport(0, 0, w, h)
       
        glMatrixMode(GL_PROJECTION)
        glLoadIdentity();
       
        aspectRatio = w / h
       
        if (w <= h):
            glOrtho (-100.0, 100.0, -100 / aspectRatio, 100.0 / 
aspectRatio, 1.0, -1.0)
        else:
            glOrtho (-100.0 * aspectRatio, 100.0 * aspectRatio, -100.0, 
100.0, 1.0, -1.0)
           
        glMatrixMode(GL_MODELVIEW)
        glLoadIdentity()
   
    def initializeGL(self):
        glClearColor(0.0, 0.0, 1.0, 1.0)

   
if __name__=='__main__':
    QApplication.setColorSpec(QApplication.CustomColor)
    app=QApplication(sys.argv)

    if not QGLFormat.hasOpenGL():
        raise 'No Qt OpenGL support.'

    widget=TestGLWidget()
    app.setMainWidget(widget)
    widget.show()
    app.exec_loop()


Now the problem that I have is that I only get a blue window, without 
the rectangle that needs to be drawn in it. Can someone help me to solve 
this problem, or am I on the wrong mailing list for this?

Thanks.

Kind regards,

Tim De Graeve


More information about the PyQt mailing list