Python Forum
How to change a value in one box change another too
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to change a value in one box change another too
#1
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))
Reply
#2
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
Reply
#3
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
Reply
#4
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.
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  event driven coding PyQt6 on Combobox change merrittr 3 1,916 May-03-2023, 03:35 AM
Last Post: merrittr
  Update exist plot while change upper limit or lower limit SamLiu 1 949 Feb-05-2023, 10:09 AM
Last Post: SamLiu
  Can't change the colour of Tk button text Pilover 6 14,501 Nov-15-2022, 10:11 PM
Last Post: woooee
  [PyQt] [Solved]Change text color of one line in TextBrowser Extra 2 4,764 Aug-23-2022, 09:11 PM
Last Post: Extra
  [Tkinter] Tkinter don't change the image DQT 2 1,560 Jul-22-2022, 10:26 AM
Last Post: menator01
  [WxPython] [SOLVED] How to change button label? Winfried 3 2,020 May-31-2022, 06:37 PM
Last Post: Winfried
  Tkinter - How can I change the default Notebook border color? TurboC 5 14,633 May-23-2022, 03:44 PM
Last Post: bigmac
Question [Tkinter] Change Treeview column color? water 3 9,418 Mar-04-2022, 11:20 AM
Last Post: Larz60+
  Can't get tkinter button to change color based on changes in data dford 4 3,363 Feb-13-2022, 01:57 PM
Last Post: dford
  how to change font size barryjo 4 3,762 Jan-26-2022, 08:46 PM
Last Post: menator01

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020