You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

在.slint文件中用TextInput创建密码框遇设置无效,求解决及示例代码

Slint TextInput 密码输入框问题解决及示例代码

正确的密码输入框实现

要在Slint里创建密码输入框,核心是给TextInput设置password: true属性,同时避免和多行属性冲突。以下是完整的可运行示例:

.slint 文件代码

export component MainWindow inherits Window {
    width: 300px;
    height: 150px;
    Column {
        spacing: 10px;
        alignment: center;
        y: 50px;
        
        TextInput {
            width: 200px;
            password: true;
            placeholder-text: "请输入密码";
            // 注意:不要设置 multiline: true,否则会和密码模式冲突导致显示异常
        }
    }
}

Rust 侧代码

slint::slint!{
    include "main.slint";
}

fn main() {
    let main_window = MainWindow::new().unwrap();
    main_window.run().unwrap();
}

两行显示异常的排查方向

  1. 检查是否启用了多行模式:如果给TextInput设置了multiline: true,会强制输入框变成多行,和password: true同时使用时会出现显示错乱(比如两行内容),必须去掉这个属性。
  2. 检查父容器布局约束:如果父容器的宽度设置过小,或者布局类型(比如Wrap)导致自动换行,也会让输入框被挤压成多行。确保父容器给TextInput足够的宽度,比如给TextInput设置固定宽度,或者让父容器的宽度能容纳输入框。

内容的提问来源于stack exchange,提问作者Panda

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.06.23 15:29:53