PyQt, Any way to use one changeValue method for multiple sliders?
<p>I need to have 3 sliders (or more). So at the moment, I have three different changeValues methods for each slider. </p>

<p>In initUI(self), I have three sliders:</p>

<pre><code>    sigmaTitle = QtGui.QLabel('Sigma')
    sigmaSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
    sigmaSlider.setRange(0, 100)
    sigmaSlider.valueChanged[int].connect(self.sigmaChangeValue)

    dtTitle = QtGui.QLabel('Sigma')
    dtSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
    dtSlider.setRange(200, 400)
    dtSlider.valueChanged[int].connect(self.dtChangeValue)

    rTitle = QtGui.QLabel('Sigma')
    rSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
    rSlider.setRange(300, 400)
    rSlider.valueChanged[int].connect(self.rChangeValue)
</code></pre>

<p>Then I have three changeValue methods:</p>

<pre><code>def sigmaChangeValue(self, value):
    self.sigma = value / 1000.0
    print self.sigma

def dtChangeValue(self, value):
    self.dt = value / 1000.0
    print self.dt

def rChangeValue(self, value):
    self.r = value / 1000.0
    print self.r
</code></pre>

<p>so is there a way to use one share changeValue method and still allow to individually assign variable with different range?</p>

<p>Thanks </p>

<p>Yes, you can connect all slider <code>valueChanged</code> signals to the same slot.
If you need to know which slider has sent the signal, you can use the <code>QObject.sender()</code> method inside the slot.
See <a href="http://pyqt.sourceforge.net/Docs/PyQt4/qobject.html#sender" rel="nofollow">QObject.sender()</a> </p>

<p>Example:</p>

<pre><code>#create the sliders using self:
self.sigmaSlider = QtGui.QSlider(QtCore.Qt.Horizontal, self)
self.sigmaSlider.setRange(0, 100)
#etc...
</code></pre>

<p>The slot:</p>

<pre><code>def mySlot(self, value):
    if self.sender() == self.sigmaSlider:
        self.sigma = value / 1000.0
        print self.sigma
    elif self.sender() == self.dtSlider:
        #etc....
</code></pre>

python qt pyqt slider