Re: size of individual widgets

Tomas Berndtsson <tomas nocrew org> writes:
> I need to be able to find the size (width/height in pixels) allocated
> for a widget, which is not displayed anywhere. I want to create a
> widget, for example a button with a given label, find out how many
> pixels in width and height it takes, and then destroy the widget
> again.
> If I do the above, I always get the width and height as 1 (one) pixel
> each, no matter what I set the label to. I get the size from
> GTK_WIDGET(button)->allocation.width/height.
> I'm using GTK+ 1.2, and I've tried to look for how to do this in the
> documentation and the FAQ, but couldn't find anything about it. Is it
> possible to find out the size of individual widgets like this?

The button won't get a size allocation until it's onscreen.

You can just call gtk_widget_size_request() to see what size it would
have requested. (This isn't necessarily the size it will end up with
in all cases if you put it onscreen, but is the "natural" size of the


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]