c++ - How to add an image to a button with GTK -


i trying add image button label, image doesn't show , broken image doesn't display either.

stop_button = gtk_button_new_with_label("stop"); image = gtk_image_new_from_file ("/home/cendit/escritorio/index.jpeg"); gtk_button_set_image (gtk_button(stop_button),image); 

i tried different path "file:///home/cendit/escritorio/index.jpeg" not successful.

images inside buttons not visible default, transitioned gtk+ 2.x 3.x. sadly, api hasn't been cleaned reflect change, it's bit of trap.

if want display button only image inside it, can use:

gtkwidget *image = gtk_image_new_from_file ("..."); gtkwidget *button = gtk_button_new ();  gtk_button_set_image (gtk_button (button), image); 

on other hand, if want have button both text , image inside it, can use:

gtkwidget *image = gtk_image_new_from_file ("..."); gtkwidget *button = gtk_button_new_with_label ("...");  gtk_button_set_always_show_image (gtk_button (button), true); gtk_button_set_image (gtk_button (button), image); 

see documentation of gtk_button_set_image() further information.


Comments

Popular posts from this blog

javascript - Clear button on addentry page doesn't work -

c# - Selenium Authentication Popup preventing driver close or quit -

tensorflow when input_data MNIST_data , zlib.error: Error -3 while decompressing: invalid block type -