Solved Is it possible to insert a "-" in lineEdit after 2 characters entered?
-
I have a lineEdit that receives a date in the format dd-mm-yyyy. Is there a function in PyQt5 that makes it possible to add the "-" in LineEdit after the 2 characters for "Day" are typed or will I have to implement it on my own?
-
@_jao_victor_
There is nothing for aQLineEdit
, that just accepts text. You would have to subclass and implement your own logic to do this.However, since this is for a date you should see QDateEdit Class which does effectively do this, and is a better choice than
QLineEdit
. It also returns the date as a date, so you don't have to parse. And you may be further interested in using its Using a Pop-up Calendar Widget optional feature. -
@_jao_victor_
There is nothing for aQLineEdit
, that just accepts text. You would have to subclass and implement your own logic to do this.However, since this is for a date you should see QDateEdit Class which does effectively do this, and is a better choice than
QLineEdit
. It also returns the date as a date, so you don't have to parse. And you may be further interested in using its Using a Pop-up Calendar Widget optional feature. -
Hi,
Depending on what you need, QLineEdit::setInputMask might be enough for your purpose.