Skip to content

Commit 6fd2b1b

Browse files
authored
Merge pull request #11 from entsecure/icon-override
Override visibleIcon and hiddenIcon when PasswordEdit is created
2 parents f86a7fa + c142848 commit 6fd2b1b

File tree

2 files changed

+32
-14
lines changed

2 files changed

+32
-14
lines changed

qtwidgets/passwordedit/password.py

+31-13
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,54 @@
1-
import sys
21
import os
2+
import sys
3+
34
from qtpy import QtCore, QtGui, QtWidgets
4-
from qtpy.QtCore import Qt
5-
from qtpy.QtCore import Signal
5+
from qtpy.QtCore import Qt, Signal
66

77
folder = os.path.dirname(__file__)
88

9+
910
class PasswordEdit(QtWidgets.QLineEdit):
1011
"""
1112
Password LineEdit with icons to show/hide password entries.
1213
Based on this example https://kushaldas.in/posts/creating-password-input-widget-in-pyqt.html by Kushal Das.
1314
"""
1415

15-
def __init__(self, show_visibility=True, *args, **kwargs):
16+
def __init__(
17+
self,
18+
show_visibility=True,
19+
visible_icon=None,
20+
hidden_icon=None,
21+
icons_from_theme=True,
22+
*args,
23+
**kwargs
24+
):
1625
super().__init__(*args, **kwargs)
1726

18-
self.visibleIcon = QtGui.QIcon(os.path.join(folder, "eye.svg"))
19-
self.hiddenIcon = QtGui.QIcon(os.path.join(folder, "hidden.svg"))
27+
if icons_from_theme:
28+
self.visibleIcon = QtGui.QIcon.fromTheme("view-visible")
29+
self.hiddenIcon = QtGui.QIcon.fromTheme("view-hidden")
30+
else:
31+
if visible_icon:
32+
self.visibleIcon = visible_icon
33+
else:
34+
self.visibleIcon = QtGui.QIcon(os.path.join(folder, "eye.svg"))
35+
if hidden_icon:
36+
self.hiddenIcon = hidden_icon
37+
else:
38+
self.hiddenIcon = QtGui.QIcon(
39+
os.path.join(folder, "hidden.svg")
40+
)
2041

2142
self.setEchoMode(QtWidgets.QLineEdit.Password)
2243

2344
if show_visibility:
2445
# Add the password hide/shown toggle at the end of the edit box.
2546
self.togglepasswordAction = self.addAction(
26-
self.visibleIcon,
27-
QtWidgets.QLineEdit.TrailingPosition
47+
self.visibleIcon, QtWidgets.QLineEdit.TrailingPosition
48+
)
49+
self.togglepasswordAction.triggered.connect(
50+
self.on_toggle_password_Action
2851
)
29-
self.togglepasswordAction.triggered.connect(self.on_toggle_password_Action)
3052

3153
self.password_shown = False
3254

@@ -39,7 +61,3 @@ def on_toggle_password_Action(self):
3961
self.setEchoMode(QtWidgets.QLineEdit.Password)
4062
self.password_shown = False
4163
self.togglepasswordAction.setIcon(self.visibleIcon)
42-
43-
44-
45-

setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
from setuptools import setup, find_packages
22

3-
version = '1.1'
3+
version = '1.2'
44

55
with open("README.md", "r") as fh:
66
long_description = fh.read()

0 commit comments

Comments
 (0)