0

I am trying to design a GUI to refresh a plot i.e. plot(timeS, dataS), using a slider corresponding to the time vector (timeS) of the data that I want to display (dataS) which is varying in time.

I have tried to connect the slider to my plot function which has a lot of input self.slider.valueChanged.connect(self.myPlotFunction(.....)), which is located in the init part of my class, but I can't use the input of the defined function myPlotFunction().

So I want that when I start dragging the slider, the plot changes according to the time/position of the slider. Moreover my time vector is made of floats while the slider allows int values.

anothernode
  • 5,100
  • 13
  • 43
  • 62
  • Possible duplicate of [Passing extra arguments through connect](https://stackoverflow.com/questions/45090982/passing-extra-arguments-through-connect) – eyllanesc Jun 26 '18 at 15:35

1 Answers1

0

When you connect a slot, you don't call the function, so

self.slider.valueChanged.connect(self.myPlotFunction(.....))

should look like

self.slider.valueChanged.connect(self.myPlotFunction)

and your definition of myPlotFunction must match the argument signature of the valueChanged signal, so

def myPlotFunction(self, sliderValue):
    # Do stuff
    pass

If you need to pass more stuff to myPlotFunction, you can use a lambda, making sure to accomodate the arguments that Qt will pass first, i.e.

otherVar = "some other stuff"
self.slider.valueChanged.connect(lambda sv, ov=otherVar: self.myPlotFunction(sv, ov))

and adjust the definition of myPlotFunction accordingly.

buck54321
  • 847
  • 9
  • 21