slint-ui / slint

Slint is a declarative GUI toolkit to build native user interfaces for Rust, C++, or JavaScript apps.
https://slint.dev
Other
17.55k stars 602 forks source link

why my lineedit losses the focus #5302

Closed Assassintears closed 2 months ago

Assassintears commented 5 months ago

I'm a fresh man to use rust and slint. My code like this:

slint:

import { Button, VerticalBox, HorizontalBox , LineEdit, TextEdit, GroupBox} from "std-widgets.slint";

export component AppWindow inherits Window {
    preferred-width: 800px;
    preferred-height: 600px;
    title: "TCP Client";
    out property <string> IP;
    out property <string> Port;
    property <string> msg;
    callback signal_connect();

    VerticalBox {
        HorizontalBox {
            Button {
                text: "IP";
            }
            line_ip:= LineEdit {
                font-size: 14px;
                placeholder-text: "Enter IP address";
                text <=> IP;
             }
             Button {
                text: "Port";
            }
            line_port := LineEdit {
                font-size: 14px;
                placeholder-text: "Enter port number";
                text <=> Port;
            }
        }

        HorizontalBox {
            Button {
                text: "Connect";
                clicked => {
                    if (IP == "" || Port == "") {
                        msg = "Please input IP and Port";
                    } else {
                        msg = IP + ":" + Port;
                    }
                    line_recv.text += msg + "\n";
                    }
            }
            Button {
                text: "Disconnect";
            }
        }

        GroupBox { 
            title: "Recv Messages";
            HorizontalBox {
                line_recv := TextEdit {
                    font-size: 14px;
                 }
                 Button {
                    text: "Clear";
                    clicked => {
                        line_recv.text = "";
                    }
                 }
            }
         }

         GroupBox {
             title: "Send Messages";
             HorizontalBox {
                TextEdit { 
                    font-size: 14px;
                 }
                 Button {
                    text: "Send";
                 }
             }
         }
    } 
}

main.rs:

slint::include_modules!();
// use slint::SharedString;
pub mod client;
use client::tcp_client;

fn main() -> Result<(), slint::PlatformError> {
    let ui = AppWindow::new()?;

    ui.on_signal_connect({
        let ui_handle = ui.as_weak();
        move || {
            let ui = ui_handle.unwrap();
            let ip = ui.get_IP();
            let port = ui.get_Port();
        }
    });
    ui.run()
}
Assassintears commented 5 months ago

if I clicked show preview like bellow, it works well. 1

Well, if I run the code with cargo run, the mainwindow will dosnt work, the textedit widget will not be selected, and the button will not be clicked.

2

Assassintears commented 5 months ago

Well, It's not a problem, when I start the app, it works well after some seconds

ogoffart commented 5 months ago

Not sure I understand the issue. Is it that just that the window don't refresh (nothing changes)

What happens if you resize the window? May be related to https://github.com/slint-ui/slint/issues/5089 and https://github.com/slint-ui/slint/issues/5206

What would happen if you put a Spinner {indeterminate: true;} just to have an animation?

Assassintears commented 4 months ago

Not sure I understand the issue. Is it that just that the window don't refresh (nothing changes)

What happens if you resize the window? May be related to #5089 and #5206

What would happen if you put a Spinner {indeterminate: true;} just to have an animation?

I'm sorry to reply you not in time. I mean I clicked the button, and the window dos not refresh

ogoffart commented 4 months ago

So it looks related to these two issues. (https://github.com/slint-ui/slint/issues/5089 and https://github.com/slint-ui/slint/issues/5206) We don't know what's causing this. I'd be very happy if you would help us debugging this. I don't know which of this is happening:

ogoffart commented 2 months ago

I'm going to assume this is the same as one of these issue and close this issue as duplicated

ryanjackgit commented 1 month ago

on windows 10.I have two windows, The first window is login window,the other is main window,The login window has two LineEdit and a image and a login button, I use another thread load image from internet,when the login window display, both two LineEdit are frozen and no focus,But login button can be clicked and trigger,.when i resize the window or full screen display manually.The two LineEdit gets work well. what's causing this.

ryanjackgit commented 1 month ago

on windows 10.I have two windows, The first window is login window,the other is main window,The login window has two LineEdit and a image and a login button, I use another thread load image from internet,when the login window display, both two LineEdit are frozen and no focus,But login button can be clicked and trigger,.when i resize the window or full screen display manually.The two LineEdit gets work well. what's causing this.

It's most likely an input method issue, when my computer defaults to English input everything works fine, but when my computer defaults to Chinese input , LineEdit doesn't get focus and can't type. Please configure your computer to use Simplified Chinese input method default initially and then start the program to test the effectiveness of LineEdit.