InputMask and SetCursorPosition



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

    ui->r5->setInputMask("HHHHHHHH"); 
    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
    Greetings


  • Qt Champions 2016

    @yczo said:

    QLineEdit

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

    http://www.qtcentre.org/threads/43273-Event-filter-with-mouse-events

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


Log in to reply
 

Looks like your connection to Qt Forum was lost, please wait while we try to reconnect.