c++gtkgtk2gtkscrolledwindow

Is it possible to set the color of a ScrollWindow?


I have the following code,:

GdkColor color;
color.red = 0x0;
color.green = 0x0;
color.blue = 0x0;

gtk_init (&argc, &argv);
window = gtk_dialog_new ();
gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &color);
g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
gtk_container_set_border_width (GTK_CONTAINER (window), 0);
gtk_widget_set_size_request (window, 300, 300);
gtk_window_fullscreen (GTK_WINDOW(window));
scrolled_window = gtk_scrolled_window_new (NULL, NULL);
gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &color);
gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window, TRUE, TRUE, 0);
gtk_widget_show (scrolled_window);
outside = gtk_table_new (10, 10, FALSE);
gtk_table_set_row_spacings (GTK_TABLE (outside), 10);
gtk_table_set_col_spacings (GTK_TABLE (outside), 10);
gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), outside);
gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &color);
gtk_widget_modify_bg(outside, GTK_STATE_NORMAL, &color);
gtk_widget_show (outside);

For some reason, the color of the window but not the scroll window is set to black. How can I change this?


Solution

  • All you need is a GtkEventBox.

    GdkColor color;
    color.red = 0x0;
    color.green = 0x0;
    color.blue = 0x0;
    
    gtk_init (&argc, &argv);
    window = gtk_dialog_new ();
    gtk_widget_modify_bg(window, GTK_STATE_NORMAL, &color);
    g_signal_connect (window, "destroy", G_CALLBACK (destroy), NULL);
    gtk_window_set_title (GTK_WINDOW (window), "GtkScrolledWindow example");
    gtk_container_set_border_width (GTK_CONTAINER (window), 0);
    gtk_widget_set_size_request (window, 300, 300);
    gtk_window_fullscreen (GTK_WINDOW(window));
    scrolled_window = gtk_scrolled_window_new (NULL, NULL);
    //gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &color);
    gtk_container_set_border_width (GTK_CONTAINER (scrolled_window), 10);
    gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (scrolled_window), GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
    gtk_box_pack_start (GTK_BOX (GTK_DIALOG(window)->vbox), scrolled_window, TRUE, TRUE, 0);
    gtk_widget_show (scrolled_window);
    outside = gtk_table_new (10, 10, FALSE);
    gtk_table_set_row_spacings (GTK_TABLE (outside), 10);
    gtk_table_set_col_spacings (GTK_TABLE (outside), 10);
    
    GtkWidget *box = gtk_event_box_new();
    gtk_container_add(GTK_CONTAINER(box), outside);
    gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), box);
    gtk_widget_modify_bg(box, GTK_STATE_NORMAL, &color);
    gtk_widget_show (box);
    
    //gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW (scrolled_window), outside);
    //gtk_widget_modify_bg(scrolled_window, GTK_STATE_NORMAL, &color);
    //gtk_widget_modify_bg(outside, GTK_STATE_NORMAL, &color);
    gtk_widget_show (outside);