Shrink window in GTK + dynamically while compressing content?

I have a window in a Vala application and an image inside it. Sometimes this image sometimes changes to img.set_from_pixbuf(imgdata); , and therefore the size changes. It is built into Gtk.Box.

 box = new Gtk.Box(Orientation.VERTICAL,5); ... box.pack_end(img,false,false); 

So, if there was a large image before, and I replace it with a smaller one, the window remains ridiculously large, and I did not find a way to dynamically reduce it to the desired location. I tried with window.set_default_size(box.width_request,box.height_request) , but it always returns -1.

So, any ideas on how to resize a window? Thanks!

+4
source share
2 answers

If I'm not mistaken, automatic resizing of windows occurs only when the elements are too large to draw. In addition, the set_default_size method only matters the first time you draw a window and, if I am mistaken, is never used again. I would suggest using the resize method to set the window size. ( link )

 window.resize(box.width_request, box.height_request); 

One thing you need to remember when using resize, if you cannot resize smaller than request_size, if you use this problem, use the set_request_size method.

+2
source

Not too deep in it, just taking a hit causing:

 box.set_resize_mode(RESIZE_IMMEDIATE); box.check_resize(); 

do the right thing?

0
source

Source: https://habr.com/ru/post/1391555/


All Articles