Search code examples
buttonpyqtpyqt4placeholderform-layout

Detect a change when values typed in placeholder


I have a form layout where I'm typing some value using QLineEdit(self).setPlaceholderText("Write your name"). I'm writing the value and I'm pressing 'OK' button and after that I need to print this value to screen. How should I do this??


Solution

  • You need to keep a reference to your lineedit, so that you can ask it what content is has later on.

    To be put in your code:

    self.q = QtGui.QLineEdit(self)
    self.q.setPlaceholderText("Write your name")
    # user does their thing
    print( self.q.text() )
    

    The last line of course goes wherever you deal with the OK button having been pressed.