In C, to obtain the actual size of the widget:widget->allocation.{width,height}To set the size (minimum size):gtk_widget_set_size_requestExample: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 PazosAUTOLogic 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 17Maybe in python is: gtk.Label.size_request()Atentamente,
Jorge Opaso PazosAUTOLogic 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.Google doesn't give much information too. _______________________________________________
There seems no answer in the pygtk API(me using Python currently). gtk.Label.get_size_request() only return (-1,-1).
gtk-list mailing list
gtk-list gnome org
http://mail.gnome.org/mailman/listinfo/gtk-list