Use pyqtProperty on QObject instance

Patrick Stinson <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <[email protected]>
I have a custom object property system that adds properties to QObject instances and am trying to expose those [dynamic] properties to qml.

Is it possible to add a qt property to a QObject instance, as opposed to adding it using pyqtProperty as a decorator in the class declaration?

The PyQt5 docs say that you can use pyqtProperty in the same way as the python property() function apart from the decorator, but I haven’t had much success with this:


def test_property():
    class A(QObject):
        def __init__(self):
            self._mine = 12
            self.mine = pyqtProperty(int, self.get_mine, self.set_mine)
        def get_mine(self):
            return self._mine
        def set_mine(self, x):
            self._mine = x

    a = A()
    print(a.mine)
    print(a.mine())



turin:pkdiagram patrick$ python test.py
<PyQt5.QtCore.pyqtProperty object at 0x114ea1840>
Traceback (most recent call last):
  File "test.py", line 743, in <module>
    test_property()
  File "test.py", line 740, in test_property
    print(a.mine())
TypeError: Required argument 'fget' (pos 1) not found
turin:pkdiagram patrick$

_______________________________________________
PyQt mailing list    [email protected]
https://www.riverbankcomputing.com/mailman/listinfo/pyqt
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.