Skip to content

Commit 2c9b291

Browse files
dfauretronical
authored andcommitted
LineEdit: implement show-password icon for the Qt style
The implementation and icon come from the material style, given that Qt itself doesn't have that feature.
1 parent 7fdf568 commit 2c9b291

File tree

3 files changed

+23
-2
lines changed

3 files changed

+23
-2
lines changed
Lines changed: 3 additions & 0 deletions
Loading
Lines changed: 3 additions & 0 deletions
Loading

internal/compiler/widgets/qt/lineedit.slint

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,12 @@
11
// Copyright © SixtyFPS GmbH <[email protected]>
22
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
33

4-
import { LineEditBase, LineEditClearIcon } from "../common/lineedit-base.slint";
4+
import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common/lineedit-base.slint";
55

66
export component LineEdit {
77
in property <length> font-size <=> inner.font-size;
88
in property <string> placeholder-text <=> inner.placeholder-text;
9-
in property input-type <=> inner.input-type;
9+
in property <InputType> input-type;
1010
in property horizontal-alignment <=> inner.horizontal-alignment;
1111
in property read-only <=> inner.read-only;
1212
in property <bool> enabled: true;
@@ -68,6 +68,7 @@ export component LineEdit {
6868
padding-bottom: native.native-padding-bottom;
6969

7070
inner := LineEditBase {
71+
input-type: root.input-type;
7172
placeholder-color: self.enabled ? NativeStyleMetrics.placeholder-color : NativeStyleMetrics.placeholder-color-disabled;
7273
text-color: self.enabled ? NativeStyleMetrics.textedit-text-color : NativeStyleMetrics.textedit-text-color-disabled;
7374
enabled: root.enabled;
@@ -90,5 +91,19 @@ export component LineEdit {
9091
}
9192
}
9293

94+
if root.input-type == InputType.password: LineEditPasswordIcon {
95+
width: self.source.width * 1px;
96+
show-password-image: @image-url("_visibility.svg");
97+
hide-password-image: @image-url("_visibility_off.svg");
98+
colorize: inner.text-color;
99+
height: inner.min-height;
100+
image-fit: preserve;
101+
show-password-changed(show) => {
102+
inner.input-type = show ? InputType.text : root.input-type;
103+
inner.focus();
104+
}
105+
}
106+
107+
93108
}
94109
}

0 commit comments

Comments
 (0)