Qt World Summit: Register Today!

InputMask and SetCursorPosition

  • Hello folks, I have a QLineEdit with an input mask:

    const QString v5aux2 = "[ 0-9,A-F]{7}";
    const QString v5aux1 = "[ 0-1]{1}";
    const QString v5 = v5aux1 + v5aux2;
    QRegExp v5E(v5);
    ui->r5->setValidator(new QRegExpValidator(v5E,this));

    The problem is that whenever I make click with the mouse, the cursor goes the mouse position.

    I know the command ui->r5->setCursorPosition(0);
    but, for the QLineEdit is not a slot called clicked()

    Then, how can i set the cursor to 0?

    Any help will wellcommed
    Thanks in advance

  • Lifetime Qt Champion

    @yczo said:


    You can subclass it and override mousePress
    or use event filter and capture the event


    void MyEdit::mouseMoveEvent(QMouseEvent *e)
    if(e->buttons() == Qt::LeftButton)

Log in to reply