Well, not so lazy… I’ve spent a couple of hours looking into this but didn’t find a solution.
Is there a way to set default size of a widget (or better just of a GtkDrawingArea) without limiting its minimum size?
It seems that the only way to have a drawing area of the size I’d want is to set a size request.
Thanks!
5 comments ↓
One trick that can be handy:
– Set the size request (minimum size) to the desired size
– Call gtk_widget_size_request() on the toplevel to find out the minimum size for the toplevel with that size widget
– Set that as the default size of the toplevel (gtk_window_set_default_size())
– Set the size request of the widget back to -1, -1
Add your drawing area to a box or table, and
setup your packing properties (expand/fill = TRUE).
Then your drawing area will always fill the allocated
space of the parent, at the toplevel window you can
specify a default size.
@Tristan: sure that’s what I do now, but there was no way (that I knew of) to compute the right default size of the toplevel to get the drawing area of the size I wanted.
@Owen: oh that’s handy! it works like a charm, thank you :)!
Would somebody care to explain in more detail how the solution from Owen works?
set_size_request sets a minimum size for the drawing area.
gtk_widget_size_request gets the toplevel size computed summing all minimum sizes of its children widgets. Then set_default_size sets the initial size of the toplevel window to the one it would have with the current size constraints and set_size_request (area, -1, -1) removes those size limits. This way you get an initial drawing area of the wanted size but no scaling down restriction.
Leave a Comment