1
votes

How do I make my string dynamically updated every time the Text value from a QLineEdit changes? I tried using signals and slots and works fine with QLabel, but not string.

self.lnEditCurrentNS = QtGui.QLineEdit(self) # This is my QLineEdit

my_string = 'none'
self.lnEditCurrentNS.textChanged.connect(self.onSelectedValue)

def onSelectedValue(self):
    selectedValue = self.txtEditCurrentNS.displayText()
    my_string = selectedValue

Let's say currently lnEditCurrentNS = 'none', then its changed to 'hello'. The value of my_string remains as 'none' instead of getting updated to 'hello'.

The value of lnEditCurrentNS got updated dynamically when the current index of a combobox I have is changed (combobox = 'hello', lnEditCurrentNS = 'hello')

I'm not very familiar with PySide/PyQt so any guidance is highly appreciated. Thanks.

1

1 Answers

0
votes

You declared my_string outside the onSelectedValue, you assigned a value inside onSelectedValue. Now if you use my_string outside the onSelectedValue, it won't give the lineEdit's text.

You can do the following trick:

self.my_string = 'None'
...

def onSelectedValue(self):
    self.my_string = self.textEditCurrentNS.text()

You can now use self.my_string at any place in the code to have the current text of the lineEdit.