0

I have multiple QSliders, QSpinBox pairs in my GUI which values I need to lock together.

Currently, this is how I implement it:

self.slider.valueChanged.connect(self.on_slider_move)
self.spinBox.valueChanged.connect(self.on_spinbox_val_change)

def on_slider_move(self, val):
   self.spinBox.setValue(val)

def on_spinbox_val_change(self, val):
   self.slider.setValue(val)

Assuming 5 (QSlider, QSpinBox) pairs, I must set 10 connections and 10 slots, with some slots performing minor changes to val.

There must be some generalized approach for this. For example, knowing who sent the signal and routing it accordingly to a specific slot:

def on_slider_move(self, sender, val):
   if sender == 'slider1':
       self.spinBox1.setValue(val)
   elif sender == 'slider2':
       self.spinBox2.setValue(val / 10)
   .
   .
   .

Unfortunately, I can't find a way to get the sender when connecting signals to slots.

What would be a good way to do this?

bdemin
  • 36
  • 1
  • 6

1 Answers1

0

The self object has a sender method.

Call below function and you can use the logic what you have said in question.

sender = self.sender()
Pavan Chandaka
  • 11,671
  • 5
  • 26
  • 34