Re: Stock image with custom text on menu item



On Mon, 2004-07-19 at 06:02, Marisa DeMeglio wrote:
I would like to create menu items that are able to use the stock 
graphics, but with custom labels.  What is the best way to do this?

Feel free to use this function:

GtkWidget*
create_custom_menu_item_from_stock(gchar* label_text,gchar *stock_id)
{
  GtkWidget* menuitem;
  GtkWidget* image;
  GtkWidget* box;
  GtkWidget* label;

  menuitem = gtk_menu_item_new();
  box = gtk_hbox_new(FALSE,0);

  image = gtk_image_new_from_stock(stock_id,GTK_ICON_SIZE_BUTTON);
  label = gtk_label_new(label_text);

  gtk_box_pack_start((GtkBox*)box,image,FALSE,FALSE,0);
  gtk_box_pack_end  ((GtkBox*)box,label,FALSE,FALSE,0);
  gtk_widget_show(label);
  gtk_widget_show(image);
  gtk_widget_show(box);
  gtk_container_add(GTK_CONTAINER(menuitem),box);

  return menuitem;
}

The quick response is, a GtkMenuItem is also a GtkBin that's a special
type of GtkContainer that can contain a single widget.

You can pack whatever you neeed in a single widget (meaning a
GtkContainer, usually a GtkBox) and add it to the GtkMenuItem ( you can
do it also with GtkButton - as example - because a GtkButton is also a
GtkBin so a GtkContainer).

See:
http://developer.gnome.org/doc/API/2.0/gtk/GtkMenuItem.html
http://developer.gnome.org/doc/API/2.0/gtk/GtkBin.html
http://developer.gnome.org/doc/API/2.0/gtk/GtkContainer.html

Hope this helps.

-- 
Iago Rubio   
- Home page    * http://www.iagorubio.com 
- Last project * http://cssed.sourceforge.net         
- GPG Keyserv  * pgp.rediris.es id=0x909BD4DD



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