PyQt6 does not allow to use the Qt.AA_UseDesktopOpenGL attribute
-
Hello,
This PySide6 example works:
import sys from OpenGL import GL as gl from PySide6.QtCore import Qt from PySide6.QtOpenGLWidgets import QOpenGLWidget from PySide6.QtWidgets import QApplication class Widget(QOpenGLWidget): def __init__(self): super().__init__() self.setWindowTitle("PySide6, OpenGL 3.3") self.resize(400, 400) def initializeGL(self): gl.glClearColor(0.5, 0.5, 0.5, 1) def paintGL(self): gl.glClear(gl.GL_COLOR_BUFFER_BIT) if __name__ == "__main__": QApplication.setAttribute(Qt.AA_UseDesktopOpenGL) app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec())
But when I translate this example to PyQt6 it does not work because it says that
'Qt' has no attribute 'AA_UseDesktopOpenGL'
:import sys from OpenGL import GL as gl from PyQt6.QtCore import Qt from PyQt6.QtOpenGLWidgets import QOpenGLWidget from PyQt6.QtWidgets import QApplication class Widget(QOpenGLWidget): def __init__(self): super().__init__() self.setWindowTitle("PyQt6, OpenGL 3.3") self.resize(400, 400) def initializeGL(self): gl.glClearColor(0.5, 0.5, 0.5, 1) def paintGL(self): gl.glClear(gl.GL_COLOR_BUFFER_BIT) if __name__ == "__main__": QApplication.setAttribute(Qt.AA_UseDesktopOpenGL) app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec())
If I delete the
QApplication.setAttribute(Qt.AA_UseDesktopOpenGL)
line of code I see the message:Traceback (most recent call last): File "main.py", line 47, in initializeGL gl.glClearColor(0.5, 0.5, 0.5, 1) File "E:\ProgramFiles\Python\Python38\lib\site-packages\OpenGL\platform\baseplatform.py", line 415, in __call__ return self( *args, **named ) File "E:\ProgramFiles\Python\Python38\lib\site-packages\OpenGL\error.py", line 230, in glCheckError raise self._errorClass( OpenGL.error.GLError: GLError( err = 1282, description = b'invalid operation', baseOperation = glClearColor, cArguments = (0.5, 0.5, 0.5, 1) )
-
musicamante gave the correct answer in the comments of this topic
PyQt6 has removed anything from Qt, it's a binding: they only changed the python access to enums, which now require the full enum scope: Qt.ApplicationAttribute.AA_UseDesktopOpenGL
import sys from OpenGL import GL as gl from PyQt6.QtCore import Qt from PyQt6.QtOpenGLWidgets import QOpenGLWidget from PyQt6.QtWidgets import QApplication class Widget(QOpenGLWidget): def __init__(self): super().__init__() self.setWindowTitle("PyQt6, OpenGL 3.3") self.resize(400, 400) def initializeGL(self): gl.glClearColor(0.5, 0.5, 0.5, 1) def paintGL(self): gl.glClear(gl.GL_COLOR_BUFFER_BIT) if __name__ == "__main__": QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseDesktopOpenGL) app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec())
-
Hi,
That's something you should bring to the PyQt author.
-
@SGaist I sent a link to this topic to this email address: pyqt@riverbankcomputing.com I found it here: https://www.riverbankcomputing.com/mailman/listinfo/pyqt
-
musicamante gave the correct answer in the comments of this topic
PyQt6 has removed anything from Qt, it's a binding: they only changed the python access to enums, which now require the full enum scope: Qt.ApplicationAttribute.AA_UseDesktopOpenGL
import sys from OpenGL import GL as gl from PyQt6.QtCore import Qt from PyQt6.QtOpenGLWidgets import QOpenGLWidget from PyQt6.QtWidgets import QApplication class Widget(QOpenGLWidget): def __init__(self): super().__init__() self.setWindowTitle("PyQt6, OpenGL 3.3") self.resize(400, 400) def initializeGL(self): gl.glClearColor(0.5, 0.5, 0.5, 1) def paintGL(self): gl.glClear(gl.GL_COLOR_BUFFER_BIT) if __name__ == "__main__": QApplication.setAttribute(Qt.ApplicationAttribute.AA_UseDesktopOpenGL) app = QApplication(sys.argv) w = Widget() w.show() sys.exit(app.exec())
-