+7 votes
by (13.6m points)

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:


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

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


2 Answers

+2 votes
by (13.6m points)

Alternatively, you could use getattr :

for id in range(1,3):
    spinbox = getattr(self, "doubleSpinBox_{}".format(id))
+1 vote
by (13.6m points)

Try this:

for spin_id in range(1,3):
  spinboxes = self.findChildren(QtGui.QDoubleSpinBox, "doubleSpinBox_%d"%spin_id)
  if spinboxes:

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