Re: How to get and set the width/height of a label?



On Fri, Aug 7, 2009 at 9:54 PM, cbx<bnucbx gmail com> wrote:
> Thank you,for your kind and your example!
> In Python,gtk.Widget.get_allocation() and gtk.Windget.allocation(as an
> attribute) return the same gtk.gdk.Rectange,which indeed is the actual size.
> So i guess get the size is a solved problem now.
>
> What i need about setting the size of the widget is not about the minimum
> one.It more like setting the 'allocation' size and not to prevent the widget
> from resizing to a smaller size by the user manually.
> Maybe it's not clear,but i don't know how to explain myself better.

What exactly do you need the label to do when it resizes ?

Currently in GTK+ the size of text is what defines the minimum
size of your interface, labels float within the space they were
allocated, using the alignment and padding rules.

I have seen hacks along the lines of:

   gtk_widget_set_size_request (widget, default_width, default_height);
   gtk_widget_show_all (toplevel);
   gtk_widget_set_size_request (widget, -1, -1);

i.e. a way to trick the hierarchy into realizing the specified widget
at a certain size, and then remove the constraint afterwords.
(Im not sure how well this works, it may break for instance if
gtk_container_check_resize() is called in the wrong place).

GtkLabels that dynamically wordwrap or ellipsize also dont come
for free (someone please correct me if Im wrong about that, I'd
like to know), i.e. tricks need to be played to synchronize the
label's size request to a size relative to the label's parent's allocation.

Cheers,
          -Tristan


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