-
|
The documentation of I want to create a simple dialog which I can show when certain events occur. This is my code: let mb = MessageBox::new().unwrap();
mb.set_mesage("Hello World".into());
mb.run().unwrap();The window opens and looks good - however, when I click the button, the window won't close. What am I doing wrong? |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
|
Right, the documentation is a bit misleading. For a rust application, you need to make it close manually with (I think it may make sense to implement that it automatically close also for other sort of application) |
Beta Was this translation helpful? Give feedback.
-
|
Thank you. I guessed already that the documentation might refer to the "user expectation" and that it does not automatically close the dialog when clicked. I think this is even the right behavior, because otherwise, there would be some hook needed in order to prevent the dialog from closing if neccessary. Might be helpful to update the documentation, though. It is not possible to call And as a follow up (and maybe it is helpful for other new slint-users), here is my new code: fn show_messagebox(message: &str) {
let mb = MessageBox::new().unwrap();
mb.set_message(message.into());
let mb_weak = mb.as_weak();
mb.on_ok_clicked(move || {
if let Some(mb) = mb_weak.upgrade() {
let _ = mb.hide();
}
});
let _ = mb.run();
}This works quite well - however, the dialog is not modal. If I run this from an event handler of another window, the calling window will still be usable. Is it possible to block interaction with other application windows as long as this window is shown? |
Beta Was this translation helpful? Give feedback.
Right, the documentation is a bit misleading.
But this only works with the slint-viewer currently.
For a rust application, you need to make it close manually with
mb.on_ok_clicked(...)(I think it may make sense to implement that it automatically close also for other sort of application)