我想给预先存在的信号增加一个新的过载。下面是一个非常简单的概念示例:
import sys
from PyQt4 import QtGui, QtCore
class MyComboBox(QtGui.QComboBox):
currentIndexChanged = QtCore.pyqtSignal(float)
def __init__(self, *args, **kwargs):
super(MyComboBox, self).__init__(*args, **kwargs)
self.currentIndexChanged[int].connect(self._on_current_changed)
def _on_current_changed(self, index):
self.currentIndexChanged[float].emit(float(index))
def log(value):
print 'value:', value
app = QtGui.QApplication(sys.argv)
combo = MyComboBox()
combo.addItems(['foo', 'bar', 'baz'])
combo.currentIndexChanged[float].connect(log)
combo.show()
sys.exit(app.exec_())
当我跑步时:
^{pr2}$我的猜测是,将新信号定义为具有相同的名称会完全覆盖现有的信号,但我不知道如何防止这种情况。在
重载与重载信号没有区别。如果要访问基类信号,可以通过
super
进行访问:相关问题 更多 >
编程相关推荐