Skip to content Skip to sidebar Skip to footer

How To Set Values In Qml Using Pyside2?

From PySide2 i want to write values into qml. This values change dynamically. For PyQt5 example here: How to set values in qml using PyQt5? main.py: import sys from PySide2.QtCore

Solution 1:

It seems that PySide2 has a bug with the setter so it does not register the Property correctly, the solution is to create a setter and getter with different names and use Property() separately to expose it:

# ...

class Foo(QObject):
    textChanged = Signal()

    def __init__(self, parent=None):
        QObject.__init__(self, parent)
        self._text = ""

    def get_text(self):
        return self._text

    def set_text(self, value):
        if self._text == value:
            return
        self._text = value
        self.textChanged.emit()

    text = Property(str, fget=get_text, fset=set_text, notify=textChanged)

# ...

Post a Comment for "How To Set Values In Qml Using Pyside2?"