[PyQt] How to get access to QOpenGLFunctions.glGetString from PyQt?

Phil Thompson phil at riverbankcomputing.com
Fri Jan 20 15:23:43 GMT 2017


On 19 Jan 2017, at 4:08 pm, Russell Warren <russ at perspexis.com> wrote:
> 
> Have you looked at the PyQt OpenGL examples?
> 
> I had not.  Thanks for the tip, I didn't know they were there.
> 
> However, they all run into this error:
> 
> ```
> $ python hellogl.py 
> Traceback (most recent call last):
>   File "hellogl.py", line 144, in initializeGL
>     self.gl = self.context().versionFunctions()
> ImportError: No module named 'PyQt5._QOpenGLFunctions_3_3_Compatibility'
> Aborted
> ```
> 
> This is interesting since I actually ran into this exact problem before when hacking around and trying to use versionFunctions() to get a hold of a QOpenGLFunctions instance. I had thought that I was doing something incorrectly, since using versionFunctions() was a bit of a guess at alternative/available ways to access QOpenGLFunctions, and was not one of the recommended ways in the Qt docs.  Here is the shortcut case for me getting that same error that I didn't post yesterday:
> 
> ```
> >>> import sys
> >>> from PyQt5 import Qt, QtWidgets, QtOpenGL
> >>> app = QtWidgets.QApplication(sys.argv)
> >>> glw = QtOpenGL.QGLWidget()
> >>> glw.glInit()
> >>> ctx = Qt.QOpenGLContext.currentContext()
> >>> ctx
> <PyQt5.QtGui.QOpenGLContext object at 0x7f55993718b8>
> >>> ctx.versionFunctions()
> Traceback (most recent call last):
>   File "<input>", line 1, in <module>
>     ctx.versionFunctions()
> ImportError: No module named 'PyQt5._QOpenGLFunctions_3_3_Compatibility'
> ```

PyQt currently only implements 2.0, 2.1 and 4.1Core. You can specify an explicit version by passing a suitably configured QOpenGLVersionProfile instance to versionFunctions().

It would be easy enough to wrap all the Qt supported versions/profiles to PyQt but that would add another 23 modules which I don't really want to do.

I know almost nothing about OpenGL and have been looking for years for somebody knowledgeable to help (by answering my dumb questions rather than writing code), but with no look so far.

> As a side note, is there a quicker way to get a valid QOpenGLContext than that (instantiating and initializing a QGLWidget)? Looks like the OpenGL demos do it with QWindow.setSurfaceType(QWindow.OpenGLSurface).

Phil


More information about the PyQt mailing list