Reputation: 83
I'm wanting to add a new overload to a pre-existing signal. Here is a very simple example of the concept:
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_())
When I run this I get:
self.currentIndexChanged[int].connect(self._on_current_changed)
KeyError: 'there is no matching overloaded signal'
My guess is that defining the new signal to have to same name completely overwrites the existing signals but I have no idea how to prevent that.
Upvotes: 1
Views: 2762
Reputation: 120578
Overloading a signal is no different than overloading a method. If you want to access the base-class signal, you can do it via super
:
super(MyComboBox, self).currentIndexChanged[int].connect(
self._on_current_changed)
Upvotes: 1