I am trying to change the color of the column headers of a treeview, with no sucess at all. I followed the way indicated in an old post in Nov. 2003:

I tried:
    for each column in the treeview:
        when defining the column, set_widget (col, label)
        now show the widget (i.e., the label).
    Then  show the treeview.
    And now:
        for each column in the treeview:
            get_widget (col)
            get_parent // the alignment
            get_parent // the hbox
            get_parent // the button
modify bg (button, state normal, some gdk color) // tried also with modify base
Result: nothing, header columns blank

I also tried in the rc file (still using gtk 2.xx):
style "TreeHeaderStyle"
 {
  bg[NORMAL] = "blue"  # tried also with base
 }
widget_class "*.GtkTreeView.GtkButton" style : highest "TreeHeaderStyle"

Result: nothing, header columns still blank

The global gtkrc is the default one and my particular gtkrc is
# Auto-written by gtk2_prefs. Do not edit.
gtk-theme-name = "Nimbus"
style "user-font"
{
    font_name="Sans 10"
}
widget_class "*" style "user-font"

I change the theme to several others and no success.
I know that some years ago the same question was made, I followed the recommendations given there. No success.

I would appreciate any help. Thanks.
Ah, in Win32.

I am attaching a small program derived from an example in the treeview tutorial
----------------- the program -------------
#include <gtk/gtk.h>

enum
{
  COL_FIRST = 0,
  NUM_COLS
} ;

static GtkTreeModel *create_and_fill_model (void)
{
  GtkTreeStore  *treestore;
  GtkTreeIter    toplevel;

  treestore = gtk_tree_store_new(NUM_COLS, G_TYPE_STRING);

  gtk_tree_store_append(treestore, &toplevel, NULL);
  gtk_tree_store_set(treestore, &toplevel, COL_FIRST, "some text", -1);

  gtk_tree_store_append(treestore, &toplevel, NULL);
  gtk_tree_store_set(treestore, &toplevel, COL_FIRST, "more text", -1);

  return GTK_TREE_MODEL(treestore);
}

void set_header (GtkTreeViewColumn *col, char *title)
{ GtkWidget *lab;

  lab = gtk_label_new (title);
  gtk_tree_view_column_set_widget (col, lab);
  gtk_widget_show (lab);
}

void set_color (GtkWidget *w, GdkColor color)
{ /* none work */
  gtk_widget_modify_bg   (w, GTK_STATE_NORMAL,      &color);
  gtk_widget_modify_base (w, GTK_STATE_NORMAL,      &color);
  gtk_widget_modify_bg   (w, GTK_STATE_ACTIVE,      &color);
  gtk_widget_modify_base (w, GTK_STATE_ACTIVE,      &color);
  gtk_widget_modify_bg   (w, GTK_STATE_PRELIGHT,    &color);
  gtk_widget_modify_base (w, GTK_STATE_PRELIGHT,    &color);
  gtk_widget_modify_bg   (w, GTK_STATE_PRELIGHT,    &color);
  gtk_widget_modify_base (w, GTK_STATE_PRELIGHT,    &color);
  gtk_widget_modify_bg   (w, GTK_STATE_SELECTED,    &color);
  gtk_widget_modify_base (w, GTK_STATE_SELECTED,    &color);
  gtk_widget_modify_bg   (w, GTK_STATE_INSENSITIVE, &color);
  gtk_widget_modify_base (w, GTK_STATE_INSENSITIVE, &color);
}

void set_color_header (GtkTreeView *view)
{
  GtkTreeViewColumn *col;
  GtkWidget         *w;
  GdkColor          color;
  gboolean          res;

  res = gdk_color_parse ("red", &color);
  if (res == 0) return;
  col = gtk_tree_view_get_column (view, COL_FIRST);

  w = gtk_tree_view_column_get_widget (col); /* the label */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the alignment */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the hbox */
  /* set_color (w, color); NOK*/

  w = gtk_widget_get_parent (w); /* the button */
  set_color (w, color); /* NOK */
}

static GtkWidget *create_view_and_model (void)
{
  GtkTreeViewColumn   *col;
  GtkCellRenderer     *renderer;
  GtkWidget           *view;
  GtkTreeModel        *model;

  view = gtk_tree_view_new();

  col = gtk_tree_view_column_new();
  set_header (col, "First Column");
  renderer = gtk_cell_renderer_text_new();
  gtk_tree_view_column_pack_start(col, renderer, TRUE);
  gtk_tree_view_column_add_attribute(col, renderer, "text", COL_FIRST);
  gtk_tree_view_append_column(GTK_TREE_VIEW(view), col);

  /* set_color_header(GTK_TREE_VIEW(view));  NOK */

  model = create_and_fill_model();

  gtk_tree_view_set_model(GTK_TREE_VIEW(view), model);

  g_object_unref(model);

  return view;
}

int main (int argc, char **argv)
{
  GtkWidget *window;
  GtkWidget *view;

  gtk_init(&argc, &argv);

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

  gtk_window_set_default_size(GTK_WINDOW(window), 300, 200);
  gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
g_signal_connect(window, "delete_event", gtk_main_quit, NULL); /* dirty */

  view = create_view_and_model();
  /*  set_color_header(GTK_TREE_VIEW(view)); NOK */

  gtk_container_add(GTK_CONTAINER(window), view);

  gtk_widget_show_all(window);

  set_color_header(GTK_TREE_VIEW(view)); /* NOK */

  gtk_main();

  return 0;
}
------------------------ the Makefile -----------------------

CC = gcc

CFLAGS = -g -O0 `pkg-config --cflags gtk+-2.0`

all: treeview-demo

treeview-demo: main.o
    gcc -o treeview-demo main.o `pkg-config --libs gtk+-2.0` -mwindows


_______________________________________________
gtk-app-devel-list mailing list
gtk-app-devel-list@gnome.org
https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list

Reply via email to