How to set icon to window in GTK Rust?

Hi,
I tried to set window icon by this code

        let window_main: gtk::Window = builder.get_object("window_main").unwrap();
        window_main.show_all();
        window_main.set_title("Czkawka");

        let icon: Pixbuf = Pixbuf::from_resource("../").unwrap();
        window_main.set_icon(Option::from(&icon));

but it shows this error(which means that this path doesn’t exists)

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { domain: g-resource-error-quark, code: 0, message: "Zasób w\u{a0}„../../icon.png” nie istnieje" }', 

I have tried to use relative and absolute paths but none works.

The “resource” methods are for loading GResource paths, not file system paths. You want from_file(), to load an image from a file.

It is not recommended to use GdkPixbuf for window icons: you should use themed icons; or, better yet, don’t use window icons at all, and specify an application icon in your .desktop launcher file, instead.

1 Like

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