Immediate Validation and editingFinished signal



  • Hi
    I want to do immediate validation of my edit lines. I want to tell the user immediately after he left the edit line field that the value he entered is maybe incorrect.

    So I connect the line edit with editingFinished() signal. However the problem is that the signal is not emitted when I click outside of the line edit, for example when I just click on the dialog. It is emitted when I click on some other line edit on the dialog. So I am looking for signal that is emitted everytime I click outside the edit line. How can I achieve this ?

    @connect(mLineEdit, SIGNAL(editingFinished()), this, SLOT(Validate()))

    MyDlg::Validate()
    {
    QString text = mLineEdit->text();
    bool isValid = check_if_valid(text);
    if(!isValid)
    // set the color of edit line to be red
    }@


  • Moderators

    Intercept the QMouseEvent from the dialog/ top level widget.



  • You mean the
    mouseMoveEvent ( QMouseEvent * ) ?

    Also, would be ok to subclass QLineEdit and override
    leaveEvent ( QEvent * ) instead ?


  • Moderators

    Mouse move is invoked a bit too often for your use case, but you can use it if you want. Mouse click event would be better. The leave event also seems good, if not the best in this situation.



  • Hi! Have you considered "QLineEdit::setValidator":http://doc-snapshot.qt-project.org/4.8/qlineedit.html#setValidator ?


Log in to reply
 

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