Use Consolas on Windows for PasswordEdit instead of the default Courier New, resolves #1226

This commit is contained in:
Janek Bevendorff 2017-11-26 16:48:09 +01:00
parent e17b3d24bf
commit 8905fe5a54

View File

@ -31,9 +31,18 @@ PasswordEdit::PasswordEdit(QWidget* parent)
{ {
setEchoMode(QLineEdit::Password); setEchoMode(QLineEdit::Password);
updateStylesheet(); updateStylesheet();
// set font to system monospace font and increase letter spacing // use a monospace font for the password field
QFont passwordFont = QFontDatabase::systemFont(QFontDatabase::FixedFont); QFont passwordFont = QFontDatabase::systemFont(QFontDatabase::FixedFont);
#ifdef Q_OS_WIN
// try to use Consolas on Windows, because the default Courier New has too many similar characters
QFont consolasFont = QFontDatabase().font("Consolas", passwordFont.styleName(), passwordFont.pointSize());
const QFont defaultFont;
if (passwordFont != defaultFont) {
passwordFont = consolasFont;
}
#endif
passwordFont.setLetterSpacing(QFont::PercentageSpacing, 110); passwordFont.setLetterSpacing(QFont::PercentageSpacing, 110);
setFont(passwordFont); setFont(passwordFont);
} }