Dear lazyweb

May 25th, 2009

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 Responses to “Dear lazyweb”

  1. Owen Taylor Says:

    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

  2. Tristan Says:

    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.

  3. fargiolas Says:

    @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 :) !

  4. Anders Says:

    Would somebody care to explain in more detail how the solution from Owen works?

  5. fargiolas Says:

    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.