Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

QLineedit cursor jumps right in hex input



  • Hi

    I need to have a Qlineedit that accepts six hexadecimal digits as input like that:
    "FF3ABD".
    I simply used:

    setInputMask("HHHHHH");
    

    for that. The problem is if I enter the first digit the cursor jumps into an rightmost empty field which seems to be not part of my input mask.

    Peek 2021-04-23 16-06.gif

    Why is that so and can this be changed to let the cursor simply jump the the next right field?



  • I think I solved it by using a QValidator instead of inputMask:

    le = new QLineEdit(this);
    QRegExp rx("([0-9]|[A-F]|[a-f]){6}");
    QValidator *valid = new QRegExpValidator(rx,this);
    le->setValidator(valid);
    

    and to always get uppercase chars when typing I added this:

    connect(le,&QLineEdit::textChanged,this,&mainwindow::textEdited);
    ...
    void mainwindow::textEdited(const QString &arg1)
    {
        le->setText(arg1.toUpper());
    }
    

    Peek 2021-04-24 08-59.gif


Log in to reply