QLineEdit text masking

I am using the PyQt4 QLineEdit widget to accept a password. There is a setMasking property, but no instructions on how to set a mask character.

+5
source share
4 answers

There are no properties setMaskingfor QLineEditin PyQt4 or Qt4. Are you talking about setInputMask()? If so, it does not do what you seem to think so. It sets a mask to validate input.

To gain control, to hide what is typed, use a method setEchoMode()that (should) display the standard password hiding character for the platform. From what I see from the documentation, if you want the custom character to be displayed, you will need to get a new class. In general, however, this is a bad idea, as it goes against what users expect to see.

+7
source
editor = QLineEdit()
editor.setEchoMode(QLineEdit.Password)
+14
source

Qt: styleHint , QStyle:: SH_LineEdit_PasswordCharacter. :

class LineEditStyle : public QProxyStyle
{
public:
    LineEditStyle(QStyle *style = 0) : QProxyStyle(style) { }

    int styleHint(StyleHint hint, const QStyleOption * option = 0,
                  const QWidget * widget = 0, QStyleHintReturn * returnData = 0 ) const
    {
        if (hint==QStyle::SH_LineEdit_PasswordCharacter)
            return '%';
        return QProxyStyle::styleHint(hint, option, widget, returnData);
    }
};

lineEdit->setEchoMode(QLineEdit::Password);
lineEdit->setStyle(new LineEditStyle(ui->lineEdit->style()));

, pyqt, , QProxyStyle; , , , , .

+3

As stated in the document http://doc-snapshot.qt-project.org/4.8/stylesheet-examples.html#customizing-qlineedit :

The password identifier for line editing, which has the QLineEdit :: Password echo mode, can be set using:

QLineEdit[echoMode="2"] {
    lineedit-password-character: 9679;
}
+1
source

All Articles