How to load and set image in GTK?


I need to set my logo in About Dialog, but I don’t want to load dynamically in already compiled bianary from disk.
I looked at source code of other project and they use relative path:

let logo = Pixbuf::from_file("data/icon.png").unwrap();

but executing binary from different path crashes app, due not finding icon.

Also I see some of sort of resource loading

let builder = gtk::Builder::from_resource("/org/eruption/eruption-gui/ui/");

but looks that also this is dynamically loaded.

I tried to use

Pixbuf::from_inline(include_bytes!("../../data/icons/com.github.qarmin.czkawka.png"), true).unwrap();

but prints this error

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { domain: gdk-pixbuf-error-quark, code: 0, message: "Image header corrupt" }', czkawka_gui/src/
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Since your using gtk-rs I would suggest looking at Boop-GTK

tl;dr: Include the icon in resources and set logo-icon-name on the about dialogue

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.