1

I'm currently testing a GTK 2 version of a program on systems using GTK 2.6, namely Ubuntu 5.04 and Fedora Core 4. I have the issue there that I am unable to create image-only buttons without a label. On later GTK versions (tested with Ubuntu 6.06, Fedora 8 and 10) this works. It looks like this:

Ubuntu 5.04 and Fedora 4 Core:

enter image description here

Ubuntu 6.06 (and similar in Fedora 8 and 10):

enter image description here

I've downloaded GTK 2.6 to find a clue in its documentation, but so far I have not found out why this is happening.

The code I use for image-only buttons is this:

GtkWidget *button = gtk_button_new ();
gtk_button_set_image (GTK_BUTTON (button), gtk_image_new_from_stock (GTK_STOCK_REMOVE, GTK_ICON_SIZE_BUTTON)); // Example

What am I missing here?

(The program is supposed to also run on old and low-end systems, that's why I am bothering with this.)

EDIT

It seems that the behaviour which I had expected was introduced with version 2.8.14, that's why it worked on Ubuntu 6.06 which uses GTK 2.10. This was not obvious to me from reading the documentation.

Packing a stock image into a button by using gtk_container_add() is a way to create labelless image-only buttons when using earlier versions.

GTK 1.2.6 fanboy
  • 839
  • 1
  • 5
  • 20
  • Low-end doesn't necessarily mean old. And these distro's support has ended ages ago, meaning they don't have any bug nor security fixes, even for the newer ones you mention. If the comportment changed it most probably is a bug that was fixed in a later version of GTK+. – liberforce Mar 08 '18 at 16:52
  • I know that these are long EOL; I did the old GTK2 versions support primarily for experimental uses for myself and maybe for a handful of other users; for the majority of users there is a GTK3 version. – GTK 1.2.6 fanboy Mar 08 '18 at 23:31

1 Answers1

0

Here's the code of gtk_button_set_image as of GTK+ 2.6.9

/**
 * gtk_button_set_image:
 * @button: a #GtkButton
 * @image: a widget to set as the image for the button
 *
 * Set the image of @button to the given widget. Note that
 * it depends on the gtk-button-images setting whether the
 * image will be displayed or not.
 *
 * Since: 2.6
 */ 
void
gtk_button_set_image (GtkButton *button,
                      GtkWidget *image)
{
  GtkButtonPrivate *priv = GTK_BUTTON_GET_PRIVATE (button);

  priv->image = image;
  priv->image_is_stock = (image == NULL);

  gtk_button_construct_child (button);

  g_object_notify (G_OBJECT (button), "image");
}

So first we can see that showing images in the buttons is handled by the gtk-buttons-images setting from your gtkrc, so you may need to force this.

We also see that setting a stock icon can be done differently: you can set as the button label the name of the stock icon, and set the use-stock property of the button to TRUE. So maybe you could try that too.

liberforce
  • 11,189
  • 37
  • 48
  • I had tried with `gtk-buttons-images` already, but that did not work, and I could not find a gtkrc setting that would set it to FALSE anyway. `use-stock` seems not to work, too; if I should get `gtk-buttons-images` or `use-stock` get to work later I will write it here though. However, I've found out that there is a way. Packing the stock images into an event box and packing this event box into the button works. So if nothing else works I will go for that. – GTK 1.2.6 fanboy Mar 08 '18 at 23:25
  • Btw. by reading the changelogs and checking the internal function `gtk_button_construct_child()` inside the GTK code I've deduced that `gtk_button_set_image()` works the way as I originally expected from version 2.8.14 onwards. Before that image and label were always supposed to appear together. – GTK 1.2.6 fanboy Mar 09 '18 at 00:23
  • Actually, directly packing into the button without using an event box is of course enough, still had creating borders around entry fields in mind... – GTK 1.2.6 fanboy Mar 09 '18 at 08:54