Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

How to edit text in line edit when echo mode is ON.



  • Hi,
    I am new to QT, I was thinking is it possible to edit some text into line edit when echo mode is ON. what i mean is line edit should not take inputs from the user but should display text when i write to it.



  • @Alam

    You mean, your LineEdit is a password input, everything the user types should be shown as dots, but the LineEdit should still show plain text to the user?!

    Have you tried "myLineedit->setText(TEXT);"
    Idk if it's working out of the box, otherwise switch echo mode off, show text and turn it on again.


  • Qt Champions 2019

    @Alam said in How to edit text in line edit when echo mode is ON.:

    what i mean is line edit should not take inputs from the user but should display text when i write to it

    This is not clear to me: what do you mean by "when i write to it"? Do you mean user edits it or do you mean you want to set the text in code? First one does not make sense, the second one is easy (see what @Pl45m4 wrote).



  • @Pl45m4 thanks for quick response. Pardon me for putting the question wrong. What I want is when in NO ECHO mode i should be able to edit any text or write any text to LineEdit using setText(). but in NO ECHO mode i'm not able to set text using setText() and displayText().



  • @jsulm Pardon me for putting the question wrong. What I wanted to convey is, I want to disable the editing functionality to user but I want the LineEdit to be used by me for displaying some text in the code. Using NO ECHO mode the user cannot edit anything in the LineEdit, this is one part of the question which serves my purpose. The other question is "is it possible to write any text into the LineEdit using setText() or displayText() in the code when in NO ECHO mode". basically I want the LineEdit to be used as just a display to the user in which I should be able to change the text and user should not have that privilege.



  • @Alam said in How to edit text in line edit when echo mode is ON.:

    What I want is when in NO ECHO mode i should be able to edit any text or write any text to LineEdit using setText(). but in NO ECHO mode i'm not able to set text using setText() and displayText().

    This makes no sense to me (Typo ON != NO ECHO MODE?)

    myLineEdit->setText("TEXT");
    

    Forces the LineEdit to show the TEXT, if nothing happend, then there is something wrong with your LineEdit initialization



  • @Alam said in How to edit text in line edit when echo mode is ON.:

    basically I want the LineEdit to be used as just a display to the user in which I should be able to change the text and user should not have that privilege

    You could use a QLabel for that purpose too. Labels are not editable, but you can show text anytime.

    And if you dont need a password input field, you can just set your QLineEdit to ReadOnly.

    myLineEdit->setReadOnly(true);
    

    This prevents the user from typing stuff in and you still can display text.

    Setting text to a label / textfield cant be that hard.....

    EDIT:

    What I want is when in NO ECHO mode i should be able to edit any text or write any text to LineEdit using setText()

    NO ECHO suppresses ANY text... so... yes, you can not display text in this mode. The text is actually there, but nothing will be displayed (-> Echo mode, in most cases, is for password inputs. NoEcho hides the password lenght, because it doesnt show anything)



  • @Pl45m4 Thank you for the solution and let me know how to make this question as solved.



  • @Alam

    There is a menu below (bottom right) your first post. If you click it, there is an option "Mark as solved"


Log in to reply