Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • Users
  • Groups
  • Search
  • Get Qt Extensions
  • Unsolved
Collapse
Brand Logo
  1. Home
  2. Qt Development
  3. General and Desktop
  4. How to make Password Echo On Edit not clear out the Previous Content
Forum Updated to NodeBB v4.3 + New Features

How to make Password Echo On Edit not clear out the Previous Content

Scheduled Pinned Locked Moved Unsolved General and Desktop
3 Posts 2 Posters 1.3k Views
  • 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.
  • T Offline
    T Offline
    TomQue
    wrote on last edited by
    #1

    I am trying to use Qlineedit password echo on edit so that it encrypts character by character but what is happing I have to focus out and when to focus back in and I type the password gets cleared. I want to b e able to type in *****b the b appears and then when I type another character like "a" the "b" gets encrypted , the password doesnt cleared and the input now looks like ******a. So far I have created a q timer that focuses out after a key has been entered and then focuses again at the timeout function but when another key is pressed the whole password gets encrypted. I read in the documentation that passwordEchoOnEedit clears out the previous content and is the only mode that does this

    1 Reply Last reply
    0
    • T Offline
      T Offline
      TomQue
      wrote on last edited by
      #2

      I have found out that I need to reimplement inputmethodEvent in my own version while inheriting QLineEdit so that it doesnt clear up however Its telling d_func is a private. How else can I access it. I need to access the d pointer. This is the function

      Q_D(QLineEdit);//<= this is where the error of that d is a private of QLineEdit
      if (d->control->isReadOnly()) {
      e->ignore();
      return;
      }
      if (echoMode() == PasswordEchoOnEdit && !d->control->passwordEchoEditing()) {
      // Clear the edit and reset to normal echo mode while entering input
      // method data; the echo mode switches back when the edit loses focus.
      // ### changes a public property, resets current content.
      d->updatePasswordEchoEditing(true);
      clear();//<= this is where it clears the password
      }
      #ifdef QT_KEYPAD_NAVIGATION
      // Focus in if currently in navigation focus on the widget
      // Only focus in on preedits, to allow input methods to
      // commit text as they focus out without interfering with focus
      if (QApplicationPrivate::keypadNavigationEnabled()
      && hasFocus() && !hasEditFocus()
      && !e->preeditString().isEmpty())
      setEditFocus(true);
      #endif
      d->control->processInputMethodEvent(e);
      #if QT_CONFIG(completer)
      if (!e->commitString().isEmpty())
      d->control->complete(Qt::Key_unknown);
      #endif

      1 Reply Last reply
      0
      • nageshN Offline
        nageshN Offline
        nagesh
        wrote on last edited by
        #3

        @TomQue as answered in the thread https://forum.qt.io/topic/125634/accessing-d-pointer-d_func-from-qlineedit-class/9

        My simplest solution for the modified behavior (not to clear the text content) of "PasswordEchoOnEdit" will be as follows.

        1)set the lineEdit "passwdEdit" echomode as "normal"
        2)connect the QApplication focusChanged signal to lambda function
        3)In lambda function check
        if last focus widget was "passwdEdit" then set echommode as "Password"
        else if Current focus is "passwdEdit" then set echommode as "Normal"

        tested code sample is as follows

        connect(qApp, &QApplication::focusChanged, [this](QWidget *oldFocus, QWidget *newFocus )
            {
                if(oldFocus == this->ui->passwdEdit)
                   this->ui->passwdEdit->setEchoMode(QLineEdit::Password);
                else if(newFocus ==this->ui->passwdEdit)  
                    this->ui->passwdEdit->setEchoMode(QLineEdit::Normal);
            }   );
        
        1 Reply Last reply
        0

        • Login

        • Login or register to search.
        • First post
          Last post
        0
        • Categories
        • Recent
        • Tags
        • Popular
        • Users
        • Groups
        • Search
        • Get Qt Extensions
        • Unsolved