Re: Problem with signal and slot arguments

Maurizio Berti <[email protected]>
Newsgroups gmane.comp.python.pyqt-pykde
Message-ID <CAPn+-XSUubYAPukh0_1LNN-WiWC8k6MKFdcSumpuYTNsCReVWw@mail.gmail.com>
Il giorno mar 29 ott 2019 alle ore 15:21 Dennis Jensen <
[email protected]> 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

_______________________________________________
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.