Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to hide password in QLineEdit

Want to hide password typed by "*". But the password is appearing as original text...

class Form(QDialog):
    def __init__(self, parent = None):
        super(Form,self).__init__(parent)

        self.usernamelabel = QLabel("Username : ")
        self.passwordlabel = QLabel("Password : ")
        self.username = QLineEdit()
        self.password = QLineEdit()
        self.okbutton = QPushButton("Login")
        self.username.setPlaceholderText("Enter Username Here")
        self.password.setPlaceholderText("Enter Password Here")

        layout = QGridLayout()
        layout.addWidget(self.usernamelabel,0,0)
        layout.addWidget(self.passwordlabel,1,0)
        layout.addWidget(self.username,0,1)
        layout.addWidget(self.password,1,1)
        layout.addWidget(self.okbutton)
        self.setLayout(layout)
like image 301
Aniruddh Chaudhari Avatar asked Mar 09 '23 16:03

Aniruddh Chaudhari


1 Answers

The QLineEdit class has several modes which allow you to control how its text is displayed. To show only asterisks (*), do this:

self.password = QLineEdit()
self.password.setEchoMode(QLineEdit.Password)
...
output = self.password.text()

PS:

To set a different password character, you can use this stylesheet property:

self.password.setStyleSheet('lineedit-password-character: 9679')

The number is a unicode code point, which in this case is for a black circle ().

like image 142
ekhumoro Avatar answered Mar 15 '23 05:03

ekhumoro