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



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.


On Sat, Aug 8, 2009 at 12:51 AM, Jorge Opaso Pazos <jorge opaso gmail com> wrote:
In C, to obtain the actual size of the widget:

widget->allocation.{width,height}

To set the size (minimum size):

gtk_widget_set_size_request

Example:

static void _label_size_allocate(GtkWidget *a_widget,
 GtkAllocation *a_alloc,
 gpointer a_data)
{
printf("size %d %d\n",
  a_widget->allocation.width,
  a_widget->allocation.height);
}


int main(int a_argc,char **a_argv)
{
GtkWidget *l_label;
GtkWidget *l_window;

gtk_init(&a_argc,&a_argv);


l_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

l_label = gtk_label_new("hello");
gtk_widget_set_size_request(GTK_WIDGET(l_label),800,600);
// To see de changes with manual resize.
g_signal_connect(G_OBJECT(l_label),
"size-allocate",
G_CALLBACK(_label_size_allocate),
NULL);

gtk_container_add(GTK_CONTAINER(l_window),l_label);
gtk_widget_show_all(l_window);


gtk_main();


return 0;
}

gtk_widget_size_allocate doesn't work for me.

Atentamente,

Jorge Opaso Pazos
AUTOLogic LTDA




El 07-08-2009, a las 9:21, cbx escribió:

I tried:in Python,it is gtk.Label.size_request().However, it only return the size the widget request to draw itself.If you resize the window,which in turn resizes the label,the value gtk.Label.size_request() returns doesn't change.

I find gtk.Widget.get_allocation() would work,even when the label is resized.It returns a gtk.gdk.Rectangle(x, y, width, height),like (0, 0, 74, 17).

And,how to set the size of gtk.Label?Is gtk.Widget.size_allocate() the answer?


On Fri, Aug 7, 2009 at 10:43 AM, Jorge Opaso Pazos <jorge opaso gmail com> wrote:
This works (C):

int main(int a_argc,char **a_argv)
{
GtkWidget *l_label;
GtkRequisition l_req;

gtk_init(&a_argc,&a_argv);

l_label = gtk_label_new("hello");
memset(&l_req,0,sizeof(GtkRequisition));
gtk_widget_size_request(l_label,&l_req); // not gtk_widget_get_size_request

printf("%d %d\n",l_req.width,l_req.height);

return 0;
}

Output: 31 17

Maybe in python is: gtk.Label.size_request() 

Atentamente,

Jorge Opaso Pazos
AUTOLogic LTDA




El 06-08-2009, a las 21:33, cbx escribió:

I would like to know how to get and set the size of a label.
There seems no answer in the pygtk API(me using Python currently). gtk.Label.get_size_request() only return (-1,-1).
Google doesn't give much information too. _______________________________________________
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list






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