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

Phil Thompson phil at riverbankcomputing.com
Fri Jan 20 22:24:47 GMT 2017


On 20 Jan 2017, at 10:14 pm, Russell Warren <russ at perspexis.com> wrote:
> 
> 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 link:
> 
> https://mail.python.org/pipermail/python-list/2016-October/715229.html
> 
> 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)
> >>> vf.GL_RENDERER
> 7937
> ```
> 
> 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>
>     vf.foo
> 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).

You haven't specified a a version, just used your systems default which you already know isn't supported.

Something like...

vp = QtGui.QOpenGLVersionProfile()
vp.setVersion(2, 1)

Phil



More information about the PyQt mailing list