GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 26, 2016 3:12 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: [SOLVED] Random icons inside buttons don't appear
PostPosted: Wed Jul 11, 2012 7:23 am 

Joined: Wed Jul 11, 2012 7:06 am
Posts: 2
I've been trying to code a simple exit program with C on Arch Linux to shutdown/restart/etc. I'm using a grid and "embedding" images on all the buttons.
What's really strange is that randomly, one image on one of the buttons chooses not to appear at all. If I try to use other image objects, the images that appeared on other buttons won't appear on the apparently buggy button. If I create a new button, with the same image used on the non-working button, it works. If I remove the faulty button object from the code, then another random button decides that it doesn't want to have an image.
If the images simply didn't exist, then an "image missing" warning image is used, which I saw earlier when experimenting.


Here's the relevant code.
   GtkWidget *window, *grid,
         *restartbutton, *shutdownbutton,
         *logoffbutton, *lockbutton,

         *irestartbutton, *ishutdownbutton,
         *ilogoffbutton, *ilockbutton;


   g_signal_connect(window, "delete-event", G_CALLBACK(gtk_main_quit), NULL);
   g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);

   gtk_container_set_border_width (GTK_CONTAINER (window), 10);

   /* Create buttons */
   shutdownbutton = gtk_button_new_with_label("Shutdown");
   restartbutton = gtk_button_new_with_label(" Restart ");
   logoffbutton = gtk_button_new_with_label(" Log Off ");
   lockbutton = gtk_button_new_with_label("   Lock    ");

   /* Define button images */
   ishutdownbutton = gtk_image_new_from_icon_name("system-shutdown",bts);
   irestartbutton = gtk_image_new_from_icon_name("reload",bts);
   ilogoffbutton = gtk_image_new_from_icon_name("system-log-out",bts);
   ilockbutton = gtk_image_new_from_icon_name("system-lock-screen",bts);

   /* Connect buttons with their functions */
   g_signal_connect(restartbutton, "clicked", G_CALLBACK(restart), NULL);
   g_signal_connect(shutdownbutton, "clicked", G_CALLBACK(shutdown), NULL);
   g_signal_connect(logoffbutton, "clicked", G_CALLBACK(logoff), NULL);
   g_signal_connect(lockbutton, "clicked", G_CALLBACK(lock), NULL);

   /* Connect images with their buttons */



   /* attach grid to window, buttons to grid */
   gtk_container_add(GTK_CONTAINER(window), grid);
   gtk_grid_attach(GTK_GRID(grid), restartbutton, 1,1,1,1);
   gtk_grid_attach(GTK_GRID(grid), lockbutton, 1,2,1,1);
   gtk_grid_attach(GTK_GRID(grid), logoffbutton, 0,2,1,1);
   gtk_grid_attach(GTK_GRID(grid), shutdownbutton, 0,1,1,1);

   gtk_window_set_decorated(GTK_WINDOW(window), FALSE);

   gtk_window_set_resizable(GTK_WINDOW(window), FALSE);
   gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);


Maybe I'm using deprecated techniques or there would be a better way to do what I want?
Thanks in advance...

edit: I switched from using a grid to a table and from GTK3 to GTK2 and the exact same problem is present on the exact same button from the "original" source code. It's probably a bug in my code...

Last edited by citanul on Fri Jul 13, 2012 12:24 am, edited 1 time in total.

 Post subject: Re: Random icons inside buttons don't appear
PostPosted: Thu Jul 12, 2012 9:57 am 

Joined: Wed Jul 11, 2012 7:06 am
Posts: 2
I fixed the problem by adding:
GtkSettings *default_settings = gtk_settings_get_default();
g_object_set(default_settings, "gtk-button-images", TRUE, NULL);

...right after gtk_init.

Source: ... t-no-image

I thought that if this "gnome configuration thing" was the issue, then none of the images on the buttons should show up... but I was wrong.

Edit: For GTK2, this "fix" doesn't work and I get:
(shutdown:16818): GLib-GObject-WARNING **: g_object_set_valist: object class `GtkSettings' has no property named `gtk-button-images'

...yet gtk-button-images seems to exist in gtk2.

Edit: For GTK2, the fix works after doing:

...before changing the property and after gtk_init().
Explanation: on the Description of

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 3 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group