GtkImageMenuItem - how do i set an image (SOLVED)

For discussions about programming, programming questions/advice, and projects that don't really have anything to do with Puppy.
Post Reply
Message
Author
User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

GtkImageMenuItem - how do i set an image (SOLVED)

#1 Post by tasmod »

I would like to add a custom icon to the menu in my firewallstate tray app and can't get my head around how to assign an image.

I checked the gtk status commands but I am not sure how to implement a custom icon.

Anyone ?? below is menu entry for a single item, note the GTK_STOCK_PREFERENCES that needs to be an icon file pointer.

iconw needs to be ' gtk_image_menu_item_set_image ' but how to point to the file?

Code: Select all

GtkWidget *menu, *menuitem, *label, *iconw ;
        menu = gtk_menu_new();
                               
        label = gtk_image_menu_item_new_with_label("Set time and date");
       iconw = gtk_image_new_from_stock(GTK_STOCK_PREFERENCES, GTK_ICON_SIZE_MENU);
       gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(label), iconw);
       gtk_menu_shell_append(GTK_MENU_SHELL(menu), label);
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

User avatar
tasmod
Posts: 1460
Joined: Thu 04 Dec 2008, 13:53
Location: North Lincolnshire. UK
Contact:

#2 Post by tasmod »

OK, I had this wrong, I needed to load from file and then set the image.

This works:-

Code: Select all

GtkWidget *menu, *menuitem, *label, *iconw, *image, *sep  ;
        menu = gtk_menu_new();

label = gtk_image_menu_item_new_with_label("Firewall ON/OFF");
	    image= gtk_image_new_from_file ("/usr/local/lib/X11/mini-icons/mini-firewall.xpm");
	    gtk_image_menu_item_set_image(GTK_IMAGE_MENU_ITEM(label), image);
	    gtk_menu_shell_append(GTK_MENU_SHELL(menu), label);
	    g_signal_connect(label, "activate", (GCallback) onoff_window, status_icon);  
Rob
-
The moment after you press "Post" is the moment you actually see the typso 8)

Post Reply