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

Russell Warren russ at perspexis.com
Thu Jan 19 16:08:51 GMT 2017


>
> 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'
```

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).

Russ
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170119/e7087cd9/attachment.html>


More information about the PyQt mailing list