Important: Please read the Qt Code of Conduct -

QLineEdit with inputmask 9999;0

  • Hi all,

    I am currently looking into a QLineEdit behaviour if I have a input maks set to a lineEdit file which shall be used for a PIN entry.

    The problem is if the user only changes 2 digits out of the 4 the lineEdit->text() only returns the changed values and not the full string.

    How can I achieve it that i get the full string back also if nothing changed?

    So default value is 0000 but if I do a linEdit->text() it just returns a empty string.

    Am I missing something?

    Many Thanks


  • Lifetime Qt Champion


    Yes, you missed a key point from the doc: The blank characters are always removed from the text after editing.

    You should add a validator to enforce the number of character entered before going further.

  • Thank you SGaist, poining to it ;)

  • Lifetime Qt Champion

    You're welcome !

    I'd also recommend using _ as placeholder char rather than 0, otherwise people will think there's a default PIN or maybe no protection at all.

Log in to reply