[Interest] Python staticmethod slot
Jérôme Godbout
godboutj at amotus.ca
Tue Feb 4 22:16:54 CET 2020
Hi,
Since the doc is pretty slim, and I have no clue how to make this work, anyone known how to call a staticmethod slot into PySide2 from Qml?
This do work:
@Slot(QVector3D, result=bool)
def myfct(self, pos: QVector3D) -> bool:
# ...
return True
But this doesn't work:
@staticmethod
@Slot(QVector3D, result=bool)
def myfct(pos: QVector3D) -> bool:
# ...
return True
How does one can call this properly?!? Do I have to make a duplicated function wrapper with the self that call the function without self just for Slot exposure? Right now the only workaround is to do this ugly mess:
@staticmethod
def myfct(pos: QVector3D) -> bool:
return True
@Slot(QVector3D, result=bool)
def myfct_qml(self, pos: QVector3D) -> bool:
"""Use _qml to change name since I cannot have the same name"""
return MyClass.myfct(pos)
I really hate to have to do this and having to create an Object Instance on top of it to call the function. Make it hard to have some Static Helper function (Q_INVOKABLE equivalent of C++) expose to Qml engine. This add up to the lack of qmlRegisterSingletonType. This is getting pretty ugly for simple function exposure.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/interest/attachments/20200204/36a5d843/attachment.html>
More information about the Interest
mailing list