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

Russell Warren russ at perspexis.com
Fri Jan 20 22:14:05 GMT 2017

> 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 thought it might be something like that.  It definitely seems sensible to
not add a bunch of modules that will usually be unused.  However, not
having them means that basically all PyQt deployments are going to fail
when you try and use this direct OpenGL functionality (since there _are_ so
many versions people will have).

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

Looking into how to make a proper QOpenGLVersionProfile, I came across this


>From that I am now a wee bit further.  No error, but I also get "None" for
the GL strings:

>>> import sys
>>> from PyQt5 import Qt, QtWidgets, QtOpenGL, QtGui
>>> app = QtWidgets.QApplication(sys.argv)
>>> glw = QtOpenGL.QGLWidget()
>>> glw.glInit()
>>> ctx = Qt.QOpenGLContext.currentContext()
>>> sf = QtGui.QSurfaceFormat()
>>> vp = QtGui.QOpenGLVersionProfile(sf)
>>> vf = ctx.versionFunctions(vp)
>>> # No error! \o/  But...
>>> vf.glGetString(vf.GL_RENDERER)
>>> vf.glGetString(vf.GL_VERSION)
>>> vf.glGetString(vf.GL_VENDOR)

All of those are obviously None.  Is this an actual NULL return due to a
problem, or is it a stub function return because the QOpenGLVersionProfile
wasn't actually configured suitably? I have no idea.

The above sequence seems to have gone with version 2.0, per this error:

>>> vf.foo
Traceback (most recent call last):
  File "<input>", line 1, in <module>
AttributeError: 'QOpenGLFunctions_2_0' object has no attribute 'foo'

I _think_ this is what I expected after reading that Qt drops to 2.0 for
compatibility (at least for Qt Quick).

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

I really wish I could help here, but I also know very little about OpenGL.
Sorry. :(

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20170120/6f91033a/attachment-0001.html>

More information about the PyQt mailing list