Scrollbars not moving when scrolling in Gtk::ScrolledWindow

I am trying to create an image viewer , by scaling a pixbuf inside an image widget to fit in window , then i add scrolled window so to allow scaling the image more than the window dimensions , the scaling works , and scrolling also works , BUT scrollbars don’t move! , Why is that?

The code:

    void set_dimensions(int &scaled_width , int &scaled_height , int available_width , int available_height , int original_width , int original_height){ 
    scaled_width = allocated_width;
    scaled_height = (scaled_width * original_height) / original_width;
    if (scaled_height > allocated_height)
    {
        scaled_height = allocated_height;
        scaled_width = (scaled_height * original_width) / original_height;
    }

    scaled_width *= scaling_factor;
    scaled_height *= scaling_factor;
}
    auto original_pixbuf = Gdk::Pixbuf::create_from_file(file);
    auto scaled_pixbuf = original_pixbuf;
    Image image(scaled_pixbuf);
    VBox box;
    box.pack_start(image , PACK_EXPAND_PADDING);
    scrolled_window.add(box);

    window.signal_size_allocate().connect([&](Allocation& a){
        allocated_width = box.get_allocation().get_width();
        allocated_height = box.get_allocation().get_height();
        set_dimensions(scaled_width , scaled_height , allocated_width , allocated_height , original_pixbuf->get_width() , original_pixbuf->get_height());

        scaled_pixbuf = original_pixbuf->scale_simple(scaled_width , scaled_height , Gdk::InterpType::INTERP_BILINEAR);
        image.set(scaled_pixbuf);
        scrolled_window.queue_compute_expand();
        scrolled_window.queue_resize();
    });

    zoom_scale.signal_change_value().connect([&](ScrollType type , double value){
        scaling_factor = zoom_scale.get_value();
        image.queue_draw();
        scrolled_window.queue_resize();
        scrolled_window.queue_compute_expand();
        return true;
    });

There is other code as well but this is the important part I think.

The full code is available here
The video showing the problem can be downloaded from here
Thanks in advance.

You cannot call queue_resize() from within size_allocate.

Also, the way you’re scaling that pixbuf is incredibly inefficient. See How to auto resize images according to window size - #8 by baedert

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