Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

why my lineedit losses the focus #5302

Open
Assassintears opened this issue May 26, 2024 · 3 comments
Open

why my lineedit losses the focus #5302

Assassintears opened this issue May 26, 2024 · 3 comments

Comments

@Assassintears
Copy link

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
Copy link
Author

Assassintears commented May 26, 2024

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
Copy link
Author

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

@ogoffart
Copy link
Member

ogoffart commented Jun 4, 2024

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants