Any way to change the above code to make it underline?
Don't think it is possible. If QLineEdit supported rich text format, you could set the text to an RTF string with the underline HTML. But it doesn't support rich text.

The closest you can get is to use QTextEdit, which does support RTF, but also has individual methods to set bold, underline, etc. But QTextEdit comes with a lot of overhead.