GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Adding a label

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
javigis
Familiar Face


Joined: 18 May 2007
Posts: 8

PostPosted: Thu Jun 14, 2007 3:40 pm    Post subject: Adding a label Reply with quote

Hi all.How can i add a label to a simple button?and how to change the size of the font?
Has anyone a little sample?
Thanks
Back to top
openldev
Never Seen the Sunlight


Joined: 21 Sep 2005
Posts: 376
Location: State College, Pennsylvania

PostPosted: Fri Jun 15, 2007 8:57 pm    Post subject: Reply with quote

GtkButton is derived from GtkBin, which means that it is a container that can hold one child. (Note that the child may be a container itself!) So, you can do the following to add a label to a button:

Code: (Plaintext)
1
2
3
4
5
6
7
8
9
10
GtkWidget *button, *label;

button = gtk_button_new ();
label = gtk_label_new ("Hello");
gtk_container_add (GTK_CONTAINER (button), label);

PangoFontDescription *fd;
fd = pango_font_description_from_string ("Sans 12");
gtk_widget_modify_font (label, fd);
pango_font_description_free (fd);


If you only want to add a label to the button, you could just create a button with gtk_button_new_with_label(). Then, create a PangoFontDescription and call gtk_widget_modify_font() on the button instead. This way is preferred. I only showed you the previous example so that you would know how to add other types of widgets to a GtkButton. (There are huge sections dedicated to this in my book, Foundations of GTK+ Development, fyi) :)
Back to top
javigis
Familiar Face


Joined: 18 May 2007
Posts: 8

PostPosted: Sun Jun 17, 2007 4:01 pm    Post subject: Reply with quote

Thanks a lot for the help. IŽll try it.
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP