Question

I have several QDoubleSpinBoxes and I want connect them to one Slot. It is possible to make one connect-command, for more than one object? for exampe, I want to connect:

doubleSpinBox_1
doubleSpinBox_2

to my function "bla". Is there any command like:

self."doubleSpinBox_1 **AND** _2".valueChanged.connect(self.bla)

?

Was it helpful?

Solution 2

Try this:

for spin_id in range(1,3):
  spinboxes = self.findChildren(QtGui.QDoubleSpinBox, "doubleSpinBox_%d"%spin_id)
  if spinboxes:
    spinboxes[0].valueChanged.connect(self.bla)

But this code is useful if you have many spinboxes to connect ;)

OTHER TIPS

Alternatively, you could use getattr:

for id in range(1,3):
    spinbox = getattr(self, "doubleSpinBox_{}".format(id))
    spinbox.valueChanged.connect(self.mySlot)
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top