Search code examples
qtqlineedit

QLineEdit to accept only one character/digit


I want to have a QLineEdit that accepts only a character or digit . Is there a possibility to set it like in html an input to have a maxlength ? I mean to do this from the constructor of QLineEdit ?

I don't need something complicated ...


Solution

  • Everything is exactly like you wanted it to be. QLineEdit has the maxLength property. You set it either using the property system, or using the setter method:

    QLineEdit le;
    le.setMaxLength(1);
    

    That's it.