Python Forum

Full Version: How to change a value in one box change another too
You're currently viewing a stripped down version of our content. View the full version with proper formatting.
Dear all,

I got one question.
There are 3 rows.
First row refer to self.bat_loss, QlineEdit
Second row is self.factor, QDoublespinbox
Third row is self.modified_loss, QlineEdit

Current progress:
First and third row are READ only.
I change factor at second row will update third row value.

But I want to include the change in third row and update second row value.
May I know how to do that?
Thanks


        self.factor.valueChanged.connect(self.valuechange)
        self.valuechange()
        concept_loss = float(self.modified_loss.text())
        concept_bat_loss = format(concept_loss, '.2f')
        self.modified_loss.setText(concept_bat_loss)


        def valuechange(self):
            self.modified_loss.setText(str(self.factor.value() * self.bat_loss))
Do exactly what you are doing for the second row. You may have to use some sort of flag to break the cycle.
def factor_changed(self):
    if not self.updating:
        self.updating = True
        self.modified_loss.setText(str(self.factor.value() * self.bat_loss))
        self.updating = False

def modified_loss_changed(self):
    if not self.updating:
        self.updating = True
        self.factor.setText(str(whatever))
        self.updating = False
Thanks deanhystad.

But how can I check whether user change the factor or modified_loss?
I mean, I plan to insert if to break the cycle.
My question now is, how I check valueChanged or textChanged in this case?

Thanks
You connect the xxxChanged signal to a function. When factor changes call the factor_changed function. When modified_loss changes calle the modified_loss_changed function. If the user changes "factor" the "factor_changed" gets called. If the usere changes "modified_loss" the "modified_loss_function" is called. Use a flag to differentiate between the user changing a control and your program changing the value of a control.