How Can I Make User Input A Simple Variable?

apex1

Regular Member
Joined
May 29, 2015
Messages
217
Reaction score
182
I'm making a GUI using PyQt5...

Lets say I have 2 input boxes in my GUI.. this code will copy the text user inputs from box 1 to box 2..

Code:
self.lineEdit.textChanged['QString'].connect(self.lineEdit_2.setText)

That works perfectly.

But lets say instead of wanting that text copied into lineEdit_2 I want it copied as a regular string variable in Python.. can someone ELI5 how this is done?

.
 
I'm making a GUI using PyQt5...

Lets say I have 2 input boxes in my GUI.. this code will copy the text user inputs from box 1 to box 2..

Code:
self.lineEdit.textChanged['QString'].connect(self.lineEdit_2.setText)

That works perfectly.

But lets say instead of wanting that text copied into lineEdit_2 I want it copied as a regular string variable in Python.. can someone ELI5 how this is done?

.

My Qt experience is with C++, so bear with me while I give advice where I shouldn't...

textChanged is a signal, with the new text as the only parameter. setText is a slot, with what to set the field to as the only parameter. When you connect these two, the parameter fired with the signal gets used in the slot call.

Try this (remember I've never done PyQt... consider this psudocode):
Code:
@pyqtSlot( 'QString' )
def apexs_slot( self, newVal ):
print( "user typed: " . newVal )

Then connect it to this slot instead of setText:
Code:
self.lineEdit.textChanged['QString'].connect( self.name_of_class.apexs_slot )

Copy/pasting that code probably won't work, but it should set you in the right direction.

Best of luck :)
 
Back
Top