Qt Forum

    • Login
    • Search
    • Categories
    • Recent
    • Tags
    • Popular
    • Users
    • Groups
    • Search
    • Unsolved

    Solved QLineedit cursor jumps right in hex input

    General and Desktop
    1
    2
    359
    Loading More Posts
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes
    Reply
    • Reply as topic
    Log in to reply
    This topic has been deleted. Only users with topic management privileges can see it.
    • pauledd
      pauledd last edited by

      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?

      1 Reply Last reply Reply Quote 0
      • pauledd
        pauledd last edited by

        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

        1 Reply Last reply Reply Quote 0
        • First post
          Last post