문제

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)

?

도움이 되었습니까?

해결책 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 ;)

다른 팁

Alternatively, you could use getattr:

for id in range(1,3):
    spinbox = getattr(self, "doubleSpinBox_{}".format(id))
    spinbox.valueChanged.connect(self.mySlot)
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top