gtk-rs / gtk

DEPRECATED, use https://github.com/gtk-rs/gtk3-rs repository instead!
https://gtk-rs.org/
MIT License
1.24k stars 82 forks source link

Problems with `gtk::Image` update through `Pixbuf` #1069

Closed Justarone closed 4 years ago

Justarone commented 4 years ago

I am a newbie, sorry in advance.
Problem: I need to change pixbuf of gtk::Image. it works in application.connect_acitvate arg-closure (where I build my window), but it doesn't work, when I try to change it inside of, for example, button.connect_clicked arg-closure.

Code (I marked places, where it works, and where not):

application.connect_activate(|app| {
        let window = gtk::ApplicationWindow::new(app);
        window.set_title("title");

        let fixed = gtk::Fixed::new();
        let pixbuf = Pixbuf::new(Colorspace::Rgb, HAS_ALPHA, BITS_PER_COLOR,
            WIDTH as i32, HEIGHT as i32).unwrap();
        let image = Image::from_pixbuf(Some(&pixbuf));

        let button = gtk::Button::with_label("something");
        fixed.add(&image);
        fixed.add(&button);
        window.add(&fixed);

        button.connect_clicked(
            clone!(image => move |_| {
        // DOESN'T WORK HERE!
                image.get_pixbuf().unwrap().fill(0xff);
            }));

        // WORKS HERE!
        pixbuf.fill(0xffff);
    });

What should I do? Help me, please..

sdroege commented 4 years ago

This is not really a bug in the bindings but more a support question or a bug in GTK. Can you ask this on the GNOME Discourse? Ideally also include a complete runnable testcase to reproduce the problem there.

Thanks :)