[PyQt] Problem with signal and slot arguments
Maurizio Berti
maurizio.berti at gmail.com
Tue Oct 29 15:47:34 GMT 2019
Il giorno mar 29 ott 2019 alle ore 15:21 Dennis Jensen <
djensen at pgcontrols.com> ha scritto:
> Actually I do not think the pyqtSlot can take that data type from what I
> understand is they only deal in primitives (int, str, object)
>
No, any python type object (even custom ones) or string representations of
Qt classes can be used:
https://www.riverbankcomputing.com/static/Docs/PyQt5/signals_slots.html#the-pyqtslot-decorator
So, all the following decorators are valid and correctly recognized (or
raise errors if the signal is not recognized as compatible):
class SomeCustomObject(object):
def __init__(self):
self.color = QtGui.QColor(QtCore.Qt.red)
class MySender(QtCore.QObject):
mySignal = QtCore.pyqtSignal([SomeCustomObject], [SomeCustomObject,
QtGui.QColor], ['QColor'])
class MyReceiver(QtCore.QObject):
@QtCore.pyqtSlot(SomeCustomObject)
def slotTest(self, obj):
print(obj.color.getRgb())
@QtCore.pyqtSlot(SomeCustomObject, QtGui.QColor)
def slotTest(self, obj, color):
print(obj.color.getRgb(), color.getRgb())
@QtCore.pyqtSlot('QColor')
def slotTest(self, color):
print(color.getRgb())
--
È difficile avere una convinzione precisa quando si parla delle ragioni del
cuore. - "Sostiene Pereira", Antonio Tabucchi
http://www.jidesk.net
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://www.riverbankcomputing.com/pipermail/pyqt/attachments/20191029/ffe57a4e/attachment.html>
More information about the PyQt
mailing list