QtPass
2.0.0
Developer documentation
Toggle main menu visibility
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
8
#include "
qpushbuttonshowpassword.h
"
9
#include <QTimer>
10
11
QPushButtonShowPassword::QPushButtonShowPassword
(QLineEdit *
line
,
12
QWidget *parent)
13
: QPushButton(parent),
14
iconEdit
(QIcon::fromTheme(
"view-visible"
, QIcon(
":/icons/view.svg"
))),
15
iconEditPushed
(
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
,
23
&
QPushButtonShowPassword::buttonClicked
);
24
this->line =
line
;
25
}
26
27
void
QPushButtonShowPassword::buttonClicked
(
bool
/*unused*/
) {
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::QPushButtonShowPassword
QPushButtonShowPassword(QLineEdit *line, QWidget *parent=nullptr)
Construct a show-password button linked to the given QLineEdit.
Definition
qpushbuttonshowpassword.cpp:11
QPushButtonShowPassword::iconEditPushed
QIcon iconEditPushed
view-hidden icon shown while the password is revealed.
Definition
qpushbuttonshowpassword.h:58
QPushButtonShowPassword::iconEdit
QIcon iconEdit
view-visible icon shown while the password is hidden.
Definition
qpushbuttonshowpassword.h:56
QPushButtonShowPassword::buttonClicked
void buttonClicked(bool checked)
Connected to QPushButton::clicked(bool); flips the echo mode of line and updates icon,...
Definition
qpushbuttonshowpassword.cpp:27
QPushButtonShowPassword::line
QLineEdit * line
The line edit being toggled; owned by the caller, must outlive this button.
Definition
qpushbuttonshowpassword.h:61
qpushbuttonshowpassword.h
Eye-icon button that toggles a QLineEdit between password and plain-text echo mode.
src
qpushbuttonshowpassword.cpp
Generated by
1.18.0