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.
- relates to
-
PYSIDE-924 Declaring a (Q)Property as "constant" does not work
-
- Closed
-