GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 8:43 am

All times are UTC




Post new topic Reply to topic  [ 13 posts ] 
Author Message
 Post subject: button background color
PostPosted: Sat Aug 25, 2012 10:38 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
I have a construction like

Code:
GdkColor colorRed2 = {0x0000, 65535, 29555, 24158};

    GtkWidget *Hbutton = gtk_button_new_with_label("H");
    gtk_grid_attach(GTK_GRID(grid), Hbutton, 0, 1, 1, 1);
    gtk_widget_modify_bg(Hbutton, GTK_STATE_NORMAL, &colorBlue);
    gtk_widget_modify_bg(Hbutton, GTK_STATE_PRELIGHT, &colorWht);


while this type of construction was working as expected with gtk2, there is a funny thing going on in gtk3. when the window is focussed, no color is shown, but when the window is out of focus, it is showing the color.

I have seen that the gtk_widget_modify_bg is deprecated in gtk 3 so I tried the suggested method with gtk_widget_override_background_color but there it seems that declaration of GdkColor colorRed2 = {0x0000, 65535, 29555, 24158} has changed to something like GdkRGBA.
I tried to change to
Code:
GdkRGBA colorRed = {1,0,0,1};
yeilding error:
Quote:
‘const struct GdkRGBA *’ but argument is of type ‘GdkRGBA’


Please help.


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sat Aug 25, 2012 11:11 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
Here is the minimal complete code that replicates the case:

Code:
#include <gtk/gtk.h>
int main(int argc,
        char *argv[]) {
    GtkWidget *window;
    GtkWidget *grid;
    GtkWidget *menubar;
    GtkWidget *filemenu;
    GtkWidget *quit;
    GtkAccelGroup *accel_group = NULL;

    gtk_init(&argc, &argv);
    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(window), "Try Grid");
    gtk_container_set_border_width(GTK_CONTAINER(window), 05);

    grid = gtk_grid_new();
    gtk_container_add(GTK_CONTAINER(window), grid);
gtk_grid_set_column_homogeneous(GTK_GRID(grid),TRUE);
gtk_grid_set_row_homogeneous(GTK_GRID(grid),TRUE);
    menubar = gtk_menu_bar_new();
    filemenu = gtk_menu_new();

    accel_group = gtk_accel_group_new();
    gtk_window_add_accel_group(GTK_WINDOW(window), accel_group);

    GtkWidget *file = gtk_menu_item_new_with_mnemonic("_File");
    quit = gtk_image_menu_item_new_from_stock(GTK_STOCK_QUIT, accel_group);

    gtk_menu_item_set_submenu(GTK_MENU_ITEM(file), filemenu);
    gtk_menu_shell_append(GTK_MENU_SHELL(filemenu), quit);
    gtk_menu_shell_append(GTK_MENU_SHELL(menubar), file);

    g_signal_connect(G_OBJECT(quit), "activate", G_CALLBACK(gtk_main_quit), NULL);

    gtk_grid_attach(GTK_GRID(grid), menubar, 0, 0, 2, 1);


    /* Color Scheme */
    GdkColor colorRed2 = {0x0000, 65535, 29555, 24158};
    GdkColor colorBlue = {0x0000, 3598, 57054, 61937};
    GdkColor colorWht = {0x0000, 65535, 65535, 65535};


    GtkWidget *Abutton = gtk_button_new_with_label("A");
    gtk_grid_attach(GTK_GRID(grid), Abutton, 0, 1, 1, 1);
    gtk_widget_modify_bg(Abutton, GTK_STATE_NORMAL, &colorBlue);
    gtk_widget_modify_bg(Abutton, GTK_STATE_PRELIGHT, &colorWht);

    /* Create second button */
    GtkWidget *Bbutton = gtk_button_new_with_label("B");
    gtk_grid_attach(GTK_GRID(grid), Bbutton, 10, 1, 1, 1);
    gtk_widget_modify_bg(Bbutton, GTK_STATE_NORMAL, &colorRed2);
    gtk_widget_modify_bg(Bbutton, GTK_STATE_PRELIGHT, &colorWht);


    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sun Aug 26, 2012 12:29 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
I will be really grateful if someone kindly help me


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sun Aug 26, 2012 6:50 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
If I'm understanding the problem correctly, I'm not seeing the same behaviour. (Tried with Ubuntu Natty, classic no effects and Unico)

Attachment:
ruda4.png
ruda4.png [ 113.18 KiB | Viewed 1380 times ]


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sun Aug 26, 2012 7:06 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
so you are getting button colors even when the window is focussed?
I am using fedora17


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sun Aug 26, 2012 7:27 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
zerohour, can you please send me the code that you used for the grid?


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sun Aug 26, 2012 9:48 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Yes, as shown in the image the colors show up when the window is in focus. I'm just using your code unaltered.


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Sun Aug 26, 2012 10:03 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
This is odd because I am getting is attached.

I am compiling it with
Code:
gcc newt.c  `pkg-config --cflags gtk+-3.0` `pkg-config --libs gtk+-3.0`

Is this same with you as well?


Attachments:
table.png
table.png [ 36.26 KiB | Viewed 1372 times ]
Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Mon Aug 27, 2012 12:22 am 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
No, that's not what I'm getting. I'm getting the button background colors for both the focused and unfocused window.
Maybe it's a Fedora issue. I'm not sure. Maybe someone else who's running on Fedora can confirm the problem your having?
I know it shouldn't be necessary here and more it's more work, but as a work-around you might try using CSS.


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Mon Aug 27, 2012 10:15 am 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
zerohour,
you are right.
The behavior I am getting only when I am using f17's theme Adwaita and few other gtk3 based theme. Old and tested themes like High/Low contrast are giving perfectly expected behavior.

Is there any way to override the theme?


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Mon Aug 27, 2012 3:09 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
As it is almost certain that this behaviour is due to f17's theme adwaita, I posted the topic in fedora forum as well(http://forums.fedoraforum.org/showpost. ... ostcount=4).
So, is there any(other then css) way to override window managers's default theme, so that, the app will look same under all and any themes used?

I have even tried zerohour's tutorial viewtopic.php?f=3&t=988&p=195463#p195463 and still getting the same behavior that notebook tabs color are not coming.


Attachments:
Untitled.png
Untitled.png [ 62.16 KiB | Viewed 1357 times ]
Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Mon Aug 27, 2012 6:36 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Quote:
Applications can override system-wide settings with gtk_settings_set_string_property(), gtk_settings_set_long_property(), etc. This should be restricted to special cases though; GtkSettings are not meant as an application configuration facility. When doing so, you need to be aware that settings that are specific to individual widgets may not be available before the widget type has been realized at least once. The following example demonstrates a way to do this:
Code:
gtk_init (&argc, &argv);

/* make sure the type is realized */
g_type_class_unref (g_type_class_ref (GTK_TYPE_IMAGE_MENU_ITEM));

g_object_set (gtk_settings_get_default (), "gtk-menu-images", FALSE, NULL);


http://developer.gnome.org/gtk3/stable/GtkSettings.html#GtkSettings.description


Top
 Profile  
 
 Post subject: Re: button background color
PostPosted: Mon Aug 27, 2012 9:50 pm 
Offline
GTK+ Guru

Joined: Sun Jul 08, 2012 3:14 pm
Posts: 107
Location: Coventry, UK
zerohour,
Thanks a lot.
Code:
g_object_set (gtk_settings_get_default (),"gtk-theme-name",NULL, NULL);

has done the trick, though buttons are not that beautiful any longer.
I have to, probably do that manually.

lets see. But thanks a lot for showing me the way.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 13 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