GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 6:42 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: How to change font size of GtkComboBox's items?
PostPosted: Thu Nov 22, 2007 10:06 am 
Offline

Joined: Wed Nov 21, 2007 8:50 am
Posts: 4
Hi all,
I need change font size of text items of GtkComboBox, but I don't know any way.
Also, I need change size of GtkComboBox in the window, maybe larger or smaller than the default size.
Please give me some way!
thank you !


Top
 Profile  
 
 Post subject:
PostPosted: Thu Nov 22, 2007 2:23 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
You can modify the font of any widget with gtk_widget_modify_font(). More information can be found at: http://library.gnome.org/devel/gtk/unst ... odify-font

You need PangoFontDescription to use this function. You can create an object of this type with pango_font_description_from_string(), found at: http://library.gnome.org/devel/pango/st ... rom-string

_________________
Andrew Krause

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


Top
 Profile  
 
 Post subject: Re:
PostPosted: Fri Nov 23, 2007 2:03 am 
Offline

Joined: Wed Nov 21, 2007 8:50 am
Posts: 4
Thank you,
But I don't know why I used gtk_widget_modify_font () unsuccessfully. This function has effective when I use for GtkLabel, GtkTextView, label on GtkButton, but GtkComboBox can't be affected.
My code:
/* create combo box*/
result->combo_marker = gtk_combo_box_new_text();
/* set font */
gtk_widget_modify_font (result->combo_marker, font_desc);
gtk_combo_box_append_text(GTK_COMBO_BOX(result->combo_marker), const gchar*)"Square");
gtk_combo_box_append_text (GTK_COMBO_BOX(result->combo_marker), (const gchar*)"Rectangle");
gtk_combo_box_set_active (GTK_COMBO_BOX(result->combo_marker), 0) ;
g_signal_connect (G_OBJECT (result->combo_marker), "changed",
G_CALLBACK (callback_option_tab_combo_marker_changed), NULL);


Other labels and text_entry in the same form are affected by this font-desc, but GtkComboBox is not.

Please help me.
Thanks!


Top
 Profile  
 
 Post subject:
PostPosted: Fri Nov 23, 2007 2:33 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 3:07 am
Posts: 384
Location: Fairfax, Virginia
I'm sorry ... I wasn't thinking when I answered your question. The modify_font() function only works if the text is rendered by the widget itself. However, the text in a combo box is managed in a GtkTreeModel (GtkListStore). You can retrieve this with gtk_combo_box_get_model(). Then, you can edit the font attributes of the corresponding GtkCellRendererText.

_________________
Andrew Krause

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


Top
 Profile  
 
 Post subject: Re:
PostPosted: Mon Nov 26, 2007 7:07 am 
Offline

Joined: Wed Nov 21, 2007 8:50 am
Posts: 4
Thanks openldev,
But when I change cellrender of gtkcombobox, it occurs 2 columns of text.
Please see my code:
result->combo_marker = gtk_combo_box_new_text();

gtk_combo_box_append_text(GTK_COMBO_BOX(result->combo_marker), (const gchar*)"Square");
gtk_combo_box_append_text (GTK_COMBO_BOX(result->combo_marker), (const gchar*)"Rectangle");
gtk_combo_box_append_text (GTK_COMBO_BOX(result->combo_marker), (const gchar*)"X");
gtk_combo_box_append_text (GTK_COMBO_BOX(result->combo_marker), (const gchar*)"+");
g_object_set (G_OBJECT(cell_renderer), "font", FONT_DESC_LEVEL_3, NULL );

gtk_cell_layout_pack_start (GTK_CELL_LAYOUT(result->combo_marker), cell_renderer, FALSE);
gtk_cell_layout_set_attributes (GTK_CELL_LAYOUT(result->combo_marker), cell_renderer, "text", 0);


and the result:


Square Square

I don't know how to just display one column (normal size ComboBoxItem)?
Help me, please.
thank,


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 03, 2007 1:50 am 
Offline

Joined: Wed Nov 21, 2007 8:50 am
Posts: 4
Ok . I was successful with it. Instead I use GtkListstore, I used GtkTreestore, and it worked.
This is my code:
Quote:
/* create combo box*/
ts = gtk_tree_store_new(1, G_TYPE_STRING);
cr = gtk_cell_renderer_text_new();
g_object_set (G_OBJECT(cr), "font", FONT_DESC_LEVEL_3, NULL );

gtk_tree_store_clear (ts);
gtk_tree_store_insert(ts, &iter, NULL, 0);
gtk_tree_store_set(ts, &iter, 0, "Just line", -1);
gtk_tree_store_insert(ts, &iter, NULL, 0);
gtk_tree_store_set(ts, &iter, 0, "Just marker", -1);
gtk_tree_store_insert(ts, &iter, NULL, 0);
gtk_tree_store_set(ts, &iter, 0, "Both", -1);

result->combo_render_style = gtk_combo_box_new_with_model(GTK_TREE_MODEL(ts));
gtk_cell_layout_pack_start(GTK_CELL_LAYOUT(result->combo_render_style),cr,FALSE);
gtk_cell_layout_set_attributes(GTK_CELL_LAYOUT(result->combo_render_style),cr,"text",0,NULL);


Note that when I use the same code with GtkListstore rather than GtkTreestore, it show 2 columns of item text. I also don't know why.
If anyone has answer for this, it's appreciated.


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 3 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