slint/internal/compiler/widgets/qt/lineedit.slint
Olivier Goffart 07c2f25698
Some checks are pending
CI / node_test (macos-14) (push) Blocked by required conditions
CI / files-changed (push) Waiting to run
CI / build_and_test (--exclude bevy-example, ubuntu-22.04, 1.85) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, --exclude bevy-example, windows-2022, 1.85) (push) Blocked by required conditions
CI / node_test (ubuntu-22.04) (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, macos-14, stable) (push) Blocked by required conditions
autofix.ci / format_fix (push) Waiting to run
autofix.ci / lint_typecheck (push) Waiting to run
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, stable) (push) Blocked by required conditions
CI / build_and_test (ubuntu-22.04, nightly) (push) Blocked by required conditions
CI / esp-idf-quick (push) Blocked by required conditions
CI / android (push) Blocked by required conditions
CI / miri (push) Blocked by required conditions
CI / test-figma-inspector (push) Blocked by required conditions
CI / build_and_test (--exclude ffmpeg --exclude gstreamer-player, windows-2022, beta) (push) Blocked by required conditions
CI / node_test (windows-2022) (push) Blocked by required conditions
CI / python_test (macos-14) (push) Blocked by required conditions
CI / python_test (ubuntu-22.04) (push) Blocked by required conditions
CI / python_test (windows-2022) (push) Blocked by required conditions
CI / cpp_test_driver (macos-13) (push) Blocked by required conditions
CI / cpp_test_driver (ubuntu-22.04) (push) Blocked by required conditions
CI / cpp_test_driver (windows-2022) (push) Blocked by required conditions
CI / cpp_cmake (macos-14, 1.85) (push) Blocked by required conditions
CI / cpp_cmake (ubuntu-22.04, stable) (push) Blocked by required conditions
CI / cpp_cmake (windows-2022, nightly) (push) Blocked by required conditions
CI / cpp_package_test (push) Blocked by required conditions
CI / vsce_build_test (push) Blocked by required conditions
CI / mcu (pico-st7789, thumbv6m-none-eabi) (push) Blocked by required conditions
CI / mcu (pico2-st7789, thumbv8m.main-none-eabihf) (push) Blocked by required conditions
CI / mcu (stm32h735g, thumbv7em-none-eabihf) (push) Blocked by required conditions
CI / mcu-embassy (push) Blocked by required conditions
CI / ffi_32bit_build (push) Blocked by required conditions
CI / docs (push) Blocked by required conditions
CI / wasm (push) Blocked by required conditions
CI / wasm_demo (push) Blocked by required conditions
CI / tree-sitter (push) Blocked by required conditions
CI / updater_test (0.3.0) (push) Blocked by required conditions
CI / fmt_test (push) Blocked by required conditions
Qt: fix show/hide password icon
Use the same code as for the fluent style
2025-09-18 13:10:49 +02:00

106 lines
3.7 KiB
Text

// Copyright © SixtyFPS GmbH <info@slint.dev>
// SPDX-License-Identifier: GPL-3.0-only OR LicenseRef-Slint-Royalty-free-2.0 OR LicenseRef-Slint-Software-3.0
import { LineEditBase, LineEditClearIcon, LineEditPasswordIcon } from "../common/lineedit-base.slint";
export component LineEdit {
in property <length> font-size <=> inner.font-size;
in property <string> placeholder-text <=> inner.placeholder-text;
in property <InputType> input-type;
in property horizontal-alignment <=> inner.horizontal-alignment;
in property read-only <=> inner.read-only;
in property <bool> enabled: true;
out property <bool> has-focus <=> inner.has-focus;
in-out property <string> text <=> inner.text;
callback accepted <=> inner.accepted;
callback edited <=> inner.edited;
callback key-pressed <=> inner.key-pressed;
callback key-released <=> inner.key-released;
accessible-role: text-input;
accessible-enabled: root.enabled;
accessible-value <=> text;
accessible-placeholder-text: text == "" ? placeholder-text : "";
accessible-read-only: root.read-only;
accessible-action-set-value(v) => { text = v; edited(v); }
public function set-selection-offsets(start: int, end: int) {
inner.set-selection-offsets(start, end);
}
public function select-all() {
inner.select-all();
}
public function clear-selection() {
inner.clear-selection();
}
public function cut() {
inner.cut();
}
public function copy() {
inner.copy();
}
public function paste() {
inner.paste();
}
forward-focus: inner;
horizontal-stretch: 1;
vertical-stretch: 0;
min-width: max(160px, layout.min-height);
min-height: max(32px, layout.min-height);
native := NativeLineEdit {
has-focus <=> root.has-focus;
enabled: root.enabled;
width: 100%;
height: 100%;
}
layout := HorizontalLayout {
padding-left: native.native-padding-left;
padding-right: native.native-padding-right;
padding-top: native.native-padding-top;
padding-bottom: native.native-padding-bottom;
inner := LineEditBase {
input-type: root.input-type;
placeholder-color: self.enabled ? NativeStyleMetrics.placeholder-color : NativeStyleMetrics.placeholder-color-disabled;
text-color: self.enabled ? NativeStyleMetrics.textedit-text-color : NativeStyleMetrics.textedit-text-color-disabled;
enabled: root.enabled;
margin: layout.padding-left + layout.padding-right;
}
if !root.text.is-empty && root.input-type != InputType.password && root.enabled && !root.read-only: Rectangle {
width: inner.min-height;
LineEditClearIcon {
width: 100%;
height: self.width;
image-fit: ImageFit.contain;
text: inner.text;
source: native.clear-icon;
colorize: inner.text-color;
clear => {
inner.text = "";
inner.focus();
}
}
}
if root.input-type == InputType.password && !root.text.is-empty && root.has-focus: LineEditPasswordIcon {
width: self.source.width * 1px;
show-password-image: @image-url("_visibility.svg");
hide-password-image: @image-url("_visibility_off.svg");
colorize: inner.text-color;
show-password: inner.input-type != InputType.password;
show-password-changed(show) => {
inner.input-type = show ? InputType.text : root.input-type;
inner.focus();
}
}
}
}