From florian, 5 Years ago, written in Plain Text.
Embed
  1. import sys
  2.  
  3. from PyQt4.QtGui import QWidget, QSlider, QApplication, QHBoxLayout
  4. from PyQt4.QtCore import Qt
  5.  
  6.  
  7. class ExampleWidget(QWidget):
  8.  
  9.     def __init__(self, parent=None):
  10.         super().__init__(parent)
  11.         self.hbox = QHBoxLayout()
  12.         self.slider1 = QSlider(Qt.Vertical, self)
  13.         self.slider2 = QSlider(Qt.Vertical, self)
  14.         self.hbox.addWidget(self.slider1)
  15.         self.hbox.addWidget(self.slider2)
  16.         self.slider1.valueChanged.connect(self.on_value_changed)
  17.         self.slider2.valueChanged.connect(self.on_value_changed)
  18.         self.setLayout(self.hbox)
  19.  
  20.     def on_value_changed(self, val):
  21.         slider = self.sender()
  22.         if slider is self.slider1:
  23.             print("Slider 1 value changed to {}".format(val))
  24.         elif slider is self.slider2:
  25.             print("Slider 2 value changed to {}".format(val))
  26.  
  27.  
  28. if __name__ == '__main__':
  29.     app = QApplication(sys.argv)
  30.     w = ExampleWidget()
  31.     w.show()
  32.     app.exec_()
  33.