bluegenetic bluegenetic - 10 months ago 82
C Question

Background color for GTK_WINDOW_TOPLEVEL Gtk Widget

In the following code, I want the background colour of the main GTK_WINDOW_TOPLEVEL to be 0xc0deed. But when I run it is appearing black. I even tried gtk_drawing_area_new and adding it to the main window. But still it is appearing black although I could get other colours like red, blue, white etc

#include <gtk/gtk.h>

int main( int argc, char *argv[])
GtkWidget *p_s_window = NULL;
GdkColor color; = 0x00C0; = 0x00DE; = 0x00ED;
gtk_init(&argc, &argv);
p_s_window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_position(GTK_WINDOW(p_s_window), GTK_WIN_POS_CENTER);
gtk_window_set_title(GTK_WINDOW(p_s_window), "hello");
gtk_widget_modify_bg(p_s_window, GTK_STATE_NORMAL, &color);
g_signal_connect_swapped(G_OBJECT(p_s_window), "destroy",
G_CALLBACK(gtk_main_quit), NULL);
return 0;

Answer Source

The GdkColor components are 16-bit, thus having a range of 0 through 65535. Multiply your values with 65535/255 and you'll be alright.

For example yellow would be: = 0xffff; = 0xffff; = 0;