Qt Forum

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

    Update: Forum Guidelines & Code of Conduct

    Immediate Validation and editingFinished signal

    General and Desktop
    3
    5
    2199
    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.
    • E
      Elii last edited by

      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
      }@

      1 Reply Last reply Reply Quote 0
      • sierdzio
        sierdzio Moderators last edited by

        Intercept the QMouseEvent from the dialog/ top level widget.

        (Z(:^

        1 Reply Last reply Reply Quote 0
        • E
          Elii last edited by

          You mean the
          mouseMoveEvent ( QMouseEvent * ) ?

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

          1 Reply Last reply Reply Quote 0
          • sierdzio
            sierdzio Moderators last edited by

            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.

            (Z(:^

            1 Reply Last reply Reply Quote 0
            • T
              terenty last edited by

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

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