pyside 信号(Signal)和槽(Slot)以及装饰器 Property和setter
1.Property的使用
class Backend(QObject):
def __init__(self) -> None:
super().__init__()
self._hello='hello_world'
@Property(str)
def hello(self):
return self._hello
qml:
text:backend.hello
2.Slot
函数方法
@Slot()
def hello_a(self):
print('hello_a>>>>')
qml:
onClicked:{
backend.hello_a()
}
3.Signal,setter
修改属性
class Backend(QObject):
helloChanged = Signal(str)
def __init__(self) -> None:
super().__init__()
self._hello='hello_world'
@Slot()
def hello_a(self):
self.hello='new_hello'
print('hello_a>>>>')
@Property(str,notify=helloChanged)
def hello(self):
return self._hello
@hello.setter
def hello(self, value):
self._hello = value
self.helloChanged.emit(self._hello)