How to change a value in one box change another too - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: GUI (https://python-forum.io/forum-10.html) +--- Thread: How to change a value in one box change another too (/thread-28812.html) |
How to change a value in one box change another too - GMCobraz - Aug-04-2020 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)) RE: How to change a value in one box change another too - deanhystad - Aug-04-2020 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 RE: How to change a value in one box change another too - GMCobraz - Aug-04-2020 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 RE: How to change a value in one box change another too - deanhystad - Aug-04-2020 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. |