Python 如何使用新样式语法检索信号参数?

Python 如何使用新样式语法检索信号参数?,python,qt,pyqt,pyside,Python,Qt,Pyqt,Pyside,在一个自定义按钮类中,我有一个信号,当有东西掉到按钮类中时,它会发出信号。以下是相关方法: class CustomButton linked = QtCore.pyqtSignal() ... def dropEvent(self, e): print e.source().objectName() print self.objectName() # set the drop action as LinkAction

在一个自定义按钮类中,我有一个信号,当有东西掉到按钮类中时,它会发出信号。以下是相关方法:

class CustomButton

   linked = QtCore.pyqtSignal()
   ...

   def dropEvent(self, e):
        print e.source().objectName()
        print self.objectName()
            # set the drop action as LinkAction
        e.setDropAction(QtCore.Qt.LinkAction)
        # tell the QDrag we accepted it
        e.accept()
        #Emit linked signal with the drag object's name as parameter
        self.linked.emit( e.source().objectName() )
        return QtGui.QPushButton.dropEvent(self, QtGui.QDropEvent(QtCore.QPoint(e.pos().x(), e.pos().y()), e.possibleActions(), e.mimeData(), e.buttons(), e.modifiers()))
另一方面,在类外,在主应用程序中,我正在创建一个插槽,以及一种将其连接到信号的方法

#The slot (actually is just a python callable)
def on_link(self):
    input = self.sender().objectName()[4:]
    print input
    #I need to print the name of the other object emitted as str parameter in the signal....

#Instance of custom button
custom_button.linked.connect( lambda: on_link( custom_button )  )

此时,我已经知道可以获取信号的
sender()
,但是,我不知道如何获取
self.linked.emit(e.source().objectName())
的参数。我只知道首先我必须先更改这个:linked=QtCore.pyqtSignal(str),但不知道如何写入连接或插槽,以及如何在emit信号中检索
e.source().objectName()

插槽的当前设计看起来非常混乱。乍一看,它看起来像一个实例方法,但实际上它只是一个模块级函数,带有一个伪
self
参数

我建议做一些更简单、更明确的事情,比如:

class CustomButton(QtGui.QPushButton):
    linked = QtCore.pyqtSignal(str, str)

    def dropEvent(self, event):
        ...
        self.linked.emit(self.objectName(), event.source().objectName())
        return QtGui.QPushButton.dropEvent(self, event)

def on_link(btn_name, src_name):
    print btn_name, src_name

custom_button.linked.connect(on_link)
另一种设计是发送对象,而不是它们的名称:

    linked = QtCore.pyqtSignal(object, object)
    ...
    self.linked.emit(self, event.source())

def on_link(button, source):
    print button.objectName(), source.objectName()