spikespaz spikespaz - 7 months ago 50
Python Question

Synchronize two element values in PyQt5

I have a slider and a text box that contains an integer (is there a dedicated integer box?) in PyQt5 shown side by side.

I need these two values to be synchronized, and the way I am doing it right now is with a QtTimer and if statements detecting if one value has changed more recently than the other, and then updating the opposite element. I was told this was "hacky" and was wondering if there was a proper way to do this.

You can see the text box values and sliders that I need to synchronize in the clear areas of the image below.

Interface example


You can just connect each of the sliders to the other one, straight-forward. I don't know the exact connection you want between the sliders, but it could look something like this.


def slider1_fu(self):
    # do stuff with the npc_stream_slider

def slider2_fu(self):
    # do stuff with the max_player_slider

Edit: Here is a Tutorial on YouTube that might be helpful.