Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. Game Development
  4. PyQt6 does not allow to use the Qt.AA_UseDesktopOpenGL attribute
Forum Updated to NodeBB v4.3 + New Features

PyQt6 does not allow to use the Qt.AA_UseDesktopOpenGL attribute

Scheduled Pinned Locked Moved Solved Game Development
5 Posts 2 Posters 2.8k Views 2 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • 8Observer88 Offline
    8Observer88 Offline
    8Observer8
    wrote on last edited by 8Observer8
    #1

    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)
    )
    
    1 Reply Last reply
    0
    • 8Observer88 Offline
      8Observer88 Offline
      8Observer8
      wrote on last edited by
      #4

      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())
      
      1 Reply Last reply
      1
      • SGaistS Offline
        SGaistS Offline
        SGaist
        Lifetime Qt Champion
        wrote on last edited by
        #2

        Hi,

        That's something you should bring to the PyQt author.

        Interested in AI ? www.idiap.ch
        Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

        8Observer88 1 Reply Last reply
        1
        • SGaistS SGaist

          Hi,

          That's something you should bring to the PyQt author.

          8Observer88 Offline
          8Observer88 Offline
          8Observer8
          wrote on last edited by
          #3

          @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

          1 Reply Last reply
          0
          • 8Observer88 Offline
            8Observer88 Offline
            8Observer8
            wrote on last edited by
            #4

            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())
            
            1 Reply Last reply
            1
            • 8Observer88 Offline
              8Observer88 Offline
              8Observer8
              wrote on last edited by
              #5

              A few basic changes in PyQt6 regarding shader-based OpenGL graphics

              1 Reply Last reply
              0

              • Login

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • Users
              • Groups
              • Search
              • Get Qt Extensions
              • Unsolved