简体   繁体   English

钩QLineEdit显示文本

[英]Hook QLineEdit showing text

Here is my problem. 这是我的问题。 I type some text into myLineEdit, for example "123456789 987654321", and I want to hide some substring in LineEdit, say "23" when displaying is hidden by another symbol "x". 我在myLineEdit中键入一些文本,例如“ 123456789 987654321”,我想在LineEdit中隐藏一些子字符串,当显示被另一个符号“ x”隐藏时说“ 23”。 That's what i want to see "1x456789 987654321", but myLineEdit->text() must still return the correct string without replacements ("123456789 987654321"). 那就是我想看到的“ 1x456789 987654321”,但是myLineEdit-> text()仍必须返回正确的字符串而不进行替换(“ 123456789 987654321”)。 So what what will help me to do this? 那么什么能帮助我做到这一点呢?

Hope this would be helpful. 希望这会有所帮助。 Instead of calling setText(QString) and text(), call setLineText(QString) and getText(). 而不是调用setText(QString)和text(),而是调用setLineText(QString)和getText()。

#include <qlineedit.h>
class LineEdit :public QLineEdit
{
    Q_OBJECT
        LineEdit();
       ~LineEdit();
       QString hide_txt="23";
     void setLineText(QString txt) {
         txt.replace(hide_txt, "x");
         setText(txt);}
     QString getText() {
         QString txt = text();
         txt.replace("x", hide_txt);
         return txt;
     }

};

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM