RE: How do you make a button out of xpm(pxmap)?
- From: martyn 2 russell bt com
- To: foreverbuddy_7070 yahoo co in, gtk-app-devel-list gnome org
- Subject: RE: How do you make a button out of xpm(pxmap)?
- Date: Wed, 4 Jun 2003 15:21:23 +0100
I'm writing an app which requires an xpm (pixmap) as
image for button ( I hope you got this.. )
and when that image is clicked..
I need to replace that image with another xpm of same
size with my function executed meanwhile...
( hope I'm clear on this too.. )
(The pixmap has not been inserted in a button widget)
Now I've drawn the pixmap, but all my attempts to
connect it to a signal handler went in vain... I tried
button_press_event, button_release_event etc.
Is there anything else I can do to achieve this?
All you should have to do is connect the signal "clicked" to the button in
question and change the image and execute the code on the callback function.
Assuming you use the same method that glade does to create a button with an
image this is how you would probably do it:
mybutton = gtk_button_new ();
gtk_container_add (GTK_CONTAINER (mywindow), mybutton);
gtk_button_set_relief (GTK_BUTTON (mybutton), GTK_RELIEF_NONE);
myalignment = gtk_alignment_new (0.5, 0.5, 0, 0);
gtk_container_add (GTK_CONTAINER (mybutton), myalignment);
myhbox = gtk_hbox_new (FALSE, 2);
gtk_container_add (GTK_CONTAINER (myalignment), myhbox);
/* myimage = gtk_image_new_from_stock ("gtk-goto-bottom",
myimage = gtk_image_new (...);
gtk_box_pack_start (GTK_BOX (myhbox), myimage, FALSE, FALSE, 0);
mylabel = gtk_label_new_with_mnemonic (_("some text"));
gtk_box_pack_start (GTK_BOX (myhbox), mylabel, FALSE, FALSE, 0);
gtk_label_set_justify (GTK_LABEL (mylabel), GTK_JUSTIFY_LEFT);
/* connect signals */
gtk_signal_connect (GTK_OBJECT (mybutton), "clicked",
void on_mybutton_clicked(GtkButton *button, gpointer user_data)
/* change the image */
gtk_image_set_from_file (myimage, "somefile.xpm");
/* do some code */
] [Thread Prev