GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Nov 28, 2014 2:32 pm

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Adding a label
PostPosted: Thu Jun 14, 2007 3:40 pm 
Offline
Familiar Face

Joined: Fri May 18, 2007 4:40 pm
Posts: 8
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


Top
 Profile  
 
 Post subject:
PostPosted: Fri Jun 15, 2007 8:57 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
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:
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) :)

_________________
Andrew Krause

Foundations of GTK+ Development: Buy now for only $31.49!


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jun 17, 2007 4:01 pm 
Offline
Familiar Face

Joined: Fri May 18, 2007 4:40 pm
Posts: 8
Thanks a lot for the help. I´ll try it.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 5 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group