31

How can I make a QLineEdit suitable for entering passwords (i.e. it doesn't show what's entered), something like the follwing:

enter image description here

AAEM
  • 1,837
  • 2
  • 18
  • 26
fafa
  • 539
  • 2
  • 7
  • 8

3 Answers3

82

setEchoMode (Documentation) for your object.

Example code:

ui->lineEditPassword->setEchoMode(QLineEdit::Password);

You can do it from Qt Designer:

enter image description here

sashoalm
  • 75,001
  • 122
  • 434
  • 781
evnu
  • 6,450
  • 2
  • 27
  • 38
11

Use setEchoMode and QLineEdit::Password

passwordField->setEchoMode(QLineEdit::Password);
4

You can using below command to hide text in lineEdit

ui->lineEditPassword->setEchoMode(QLineEdit::Password);
Donald Duck
  • 8,409
  • 22
  • 75
  • 99
thacngoc
  • 49
  • 1
  • 2
  • This exact answer has already been submitted by someone else. Please try to avoid duplicate answers. – Yun Sep 05 '21 at 07:09