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

Need API to programmatically close child window after form submission #6641

Closed
sadlrxn opened this issue Oct 24, 2024 · 1 comment
Closed

Comments

@sadlrxn
Copy link

sadlrxn commented Oct 24, 2024

Description

I'm working on a Slint UI application where my main window contains a button that opens a new child window with a form. I want to automatically close this child window after the form is successfully submitted (when no validation errors are found).

Currently, window closing is only handled through the on_close_request event, which is triggered by window management actions (like clicking the X button). However, I need a way to programmatically close the window from within my code after form submission.

Current Behavior

  • Main window opens child window via button click
  • Form submission is processed
  • Window remains open even after successful submission
  • Window can only be closed through window manager actions

Desired Behavior

  • Main window opens child window via button click
  • Form submission is processed
  • If submission is successful (no errors), window automatically closes
  • If submission has errors, window remains open

Question

Is there an API method available to programmatically close a Slint window? Looking for something similar to:

// Pseudo-code of what I'm looking for
if form_submission.is_successful() {
    child_window.close();
}

or

  • The on_close_request event handler is not sufficient for this use case as it only handles window manager close events
  • Need a programmatic way to trigger window closure from within the application logic

similar issue: #5465 marked answered but it's not.

@Enyium
Copy link
Contributor

Enyium commented Oct 24, 2024

I think hide() is the way to do this. As its and show()s docs say, a strong reference to the component is internally maintained by Slint, while the window is visible. I.e., you can visually hide the window, which is already the closing from the end user's perspective (and discards the internal strong reference), and then it's up to you whether you want to cause the window component instance to be destroyed by dropping it (the only strong instance left; many things are like Rc in Slint).

@sadlrxn sadlrxn closed this as completed Oct 24, 2024
@sadlrxn sadlrxn reopened this Oct 24, 2024
@sadlrxn sadlrxn closed this as completed Oct 24, 2024
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