Skip to content

@image-url from a property<string> #3437

Answered by tronical
microhobby asked this question in Q&A
Discussion options

You must be logged in to vote

Hi! You can use the C++ and Rust APIs of slint::Image to load an image at runtime from a path, and then set the image property.

That means that you can correctly compute the absolute path at runtime and handle errors if the file does not exist.

In theory we could allow arbitrary strings at runtime, but I feel that should use a function instead of a macro (@image-url), we would have to decide how to handle relative paths, we might need API to construct paths, and introduce features to make error handling ergonomic. That would seem like a direction to me that's closer to business logic, which I think we may want to minimize in .Slint files, also to keep them toolable.

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by microhobby
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants