QtPass 2.0.0
Developer documentation
Loading...
Searching...
No Matches
qpushbuttonshowpassword.cpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2020 Anne Jan Brouwer
2// SPDX-License-Identifier: GPL-3.0-or-later
9#include <QTimer>
10
12 QWidget *parent)
13 : QPushButton(parent),
14 iconEdit(QIcon::fromTheme("view-visible", QIcon(":/icons/view.svg"))),
16 QIcon::fromTheme("view-hidden", QIcon(":/icons/hide.svg"))) {
17 setIcon(iconEdit);
18 // Icon-only: give screen readers and hovering users a name.
19 setToolTip(tr("Show password"));
20 setAccessibleName(tr("Show password"));
21 setForegroundRole(QPalette::ButtonText);
22 connect(this, &QPushButton::clicked, this,
24 this->line = line;
25}
26
28 if (this->line->echoMode() == QLineEdit::Password) {
29 this->line->setEchoMode(QLineEdit::Normal);
30 setIcon(iconEditPushed);
31 setToolTip(tr("Hide password"));
32 setAccessibleName(tr("Hide password"));
33 } else {
34 this->line->setEchoMode(QLineEdit::Password);
35 setIcon(iconEdit);
36 setToolTip(tr("Show password"));
37 setAccessibleName(tr("Show password"));
38 }
39}
QPushButtonShowPassword(QLineEdit *line, QWidget *parent=nullptr)
Construct a show-password button linked to the given QLineEdit.
QIcon iconEditPushed
view-hidden icon shown while the password is revealed.
QIcon iconEdit
view-visible icon shown while the password is hidden.
void buttonClicked(bool checked)
Connected to QPushButton::clicked(bool); flips the echo mode of line and updates icon,...
QLineEdit * line
The line edit being toggled; owned by the caller, must outlive this button.
Eye-icon button that toggles a QLineEdit between password and plain-text echo mode.