Question: Consider a simple example like this which links two sliders using signals and slots:

```
from PySide.QtCore import *
from PySide.QtGui import *
import sys

class MyMainWindow(QWidget):
 def __init__(self):
  QWidget.__init__(self, None)

  vbox = QVBoxLayout()

  sone = QSlider(Qt.Horizontal)
  vbox.addWidget(sone)

  stwo = QSlider(Qt.Horizontal)
  vbox.addWidget(stwo)

  sone.valueChanged.connect(stwo.setValue)

if __name__ == '__main__':
 app = QApplication(sys.argv)
 w = MyMainWindow()
 w.show()
 sys.exit(app.exec_())

```

How would you change this so that the second slider moves in the opposite direction as the first? Slider one would be initialized with these values:

```
  sone.setRange(0,99)
  sone.setValue(0)

```

And slider two would be initialized with these values:

```
  stwo.setRange(0,99)
  stwo.setValue(99)

```

And then the value of stwo would be `99 - sone.sliderPosition`.

How would you implement the signal and slot to make this work? I would appreciate a working example that builds on the simple example above.

Answer: 
You can connect signals to functions that do things. Your code isn't structured to do that easily and required refactoring, so you can do it the easy way:

```
stwo.setInvertedAppearance(True)
sone.valueChanged.connect(stwo.setValue)

```
Here's the way I did it. I added this class which reimplements setValue. (I got the idea from <http://zetcode.com/tutorials/pyqt4/eventsandsignals/>)

```
class MySlider(QSlider):
    def __init__(self):
        QSlider.__init__(self, Qt.Horizontal)

    def setValue(self, int):
        QSlider.setValue(self, 99-int)

```

Here's the complete code. Is this a good approach?

```
from PySide.QtCore import *
from PySide.QtGui import *
import sys

class MySlider(QSlider):
    def __init__(self):
        QSlider.__init__(self, Qt.Horizontal)

    def setValue(self, int):
        QSlider.setValue(self, 99-int)

class MyMainWindow(QWidget):
 def __init__(self):
  QWidget.__init__(self, None)

  vbox = QVBoxLayout()

  sone = QSlider(Qt.Horizontal)
  sone.setRange(0,99)
  sone.setValue(0)
  vbox.addWidget(sone)

  stwo = MySlider()
  stwo.setRange(0,99)
  stwo.setValue(0)
  vbox.addWidget(stwo)

  sone.valueChanged.connect(stwo.setValue)

  self.setLayout(vbox)

if __name__ == '__main__':
    app = QApplication(sys.argv)
    w = MyMainWindow()
    w.show()
    sys.exit(app.exec_())

```