PyQt过载预先存在的信号

2024-09-27 09:34:46 发布

您现在位置:Python中文网/ 问答频道 /正文

我想给预先存在的信号增加一个新的过载。下面是一个非常简单的概念示例:

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}$

我的猜测是,将新信号定义为具有相同的名称会完全覆盖现有的信号,但我不知道如何防止这种情况。在


Tags: importself信号initvaluedefsysargs

热门问题