Restrict QLineEdit input to single character PyQt5

Viewed 1370

I am making a PyQt5 application. I want to restrict the user to be able to enter only a single character in a QLineEdit object. Is this possible? If so, how?

Thanks in advance. :)

1 Answers

QLineEdit has the maxLength property.

setMaxLength()

Sets the maximum number of characters for input

e1 = QLineEdit()
e1.setMaxLength(1)
Related