Uploaded image for project: 'Qt for Python'
  1. Qt for Python
  2. PYSIDE-3227

QtCore.Property decorator marks all properties writable in QMetaObject

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P3: Somewhat important P3: Somewhat important
    • 6.10.1, 6.11.0
    • 6.10.0
    • PySide
    • None
    • All
    • 2aff6a35a (dev), 2fb8c971d (6.10)

      Using QtCore.Property as a decorator marks all properties writable, even if no setter is defined.

       

      from PySide6.QtCore import QObject, Property
       
      class A(QObject):
          @Property(int)
          def x(self):
              return 10
      

      A().metaObject() yields

      PySide6.QtCore.QMetaObject("A" inherits "QObject": 
      Properties: 
       #1 "x", int [writeable] [resettable] [designable] 
      )

      A().metaObject().property(0).isWritable() is True

      Calling Property explicitly works,

      class B(QObject):
          def _x(self):
              return 10
              
          x = Property(int, _x)

      B().metaObject() yields

      PySide6.QtCore.QMetaObject("B" inherits "QObject": 
      Properties: 
       #1 "x", int [designable] 
      )

      B().metaObject().property(0).isWritable() is False
       
      However, explicitly setting fset=None doesn't work,

      class C(QObject):
          def _x(self):
              return 10
              
          x = Property(int, _x, None)

      C().metaObject() yields

      PySide6.QtCore.QMetaObject("C" inherits "QObject": 
      Properties: 
       #1 "x", int [writeable] [designable] 
      )

      C().metaObject().property(0).isWritable() is True

      Also, only for B the proper AttributeError is raised when trying to write the property. In the other cases it is TypeError: 'NoneType' object is not callable.

      The same problem likely exists for reset.

        For Gerrit Dashboard: PYSIDE-3227
        # Subject Branch Project Status CR V

            kleint Friedemann Kleint
            lschr Lukas Schrangl
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

              Created:
              Updated:
              Resolved: