Re: Treeviews: changing the color of column headers
- From: "Juan L. Freniche" <fdesp87 gmail com>
- To: gtk-list gnome org
- Subject: Re: Treeviews: changing the color of column headers
- Date: Sat, 13 Jun 2015 19:23:17 +0200
More info:
I copy a small program (derived from some other program found in the
treeview tutorial) and the Makefile. All things that I tried didn't
change the background of the header treeview colum.
What is missing or wrong?
----------------- 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
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]