Re: Treeview (liststore) CSS question
- From: Mike Martin <redtux1 gmail com>
- To: cecashon aol com
- Cc: Daniel Kasak <d j kasak dk gmail com>, gtk-app-devel-list <gtk-app-devel-list gnome org>
- Subject: Re: Treeview (liststore) CSS question
- Date: Thu, 21 Mar 2019 15:11:46 +0000
apologies I did resolve my issue , posted as wrong person
Resolved my issue, turns out I needed some voodoo with properties
$widgetpage{file_scroll}->set('propagate_natural_height','1');
$widgetpage{file_scroll}->set_vexpand(0);
On Tue, 19 Mar 2019 at 18:53, <cecashon aol com> wrote:
Hi Mike,
Have you tried
gtk_widget_set_vexpand(tree, FALSE);
on the treeview? This might work to show a different background color on
the unused space of the treeview.
I don't know if this is of any help but also remember that you can set
individual row colors in a treeview by having a color column. That way you
can add some logic into what color the row is. Also, a selection color is
easy to set with CSS.
Eric
//gcc -Wall stripe_list1.c -o stripe_list1 `pkg-config --cflags --libs
gtk+-3.0`
#include<gtk/gtk.h>
enum
{
ID,
PROGRAM,
COLOR,
COLUMNS
};
int main(int argc, char *argv[])
{
gtk_init(&argc, &argv);
GtkWidget *window=gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(window), "Stripes");
gtk_window_set_position(GTK_WINDOW(window), GTK_WIN_POS_CENTER);
gtk_window_set_default_size(GTK_WINDOW(window), 300, 300);
gtk_widget_set_name(window, "main_window");
g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
GtkTreeIter iter;
GtkListStore *store=gtk_list_store_new(COLUMNS, G_TYPE_UINT,
G_TYPE_STRING, G_TYPE_STRING);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, 0, PROGRAM, "Gedit", COLOR,
"cyan", -1);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, 1, PROGRAM, "Gimp", COLOR,
"yellow", -1);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, 2, PROGRAM, "Inkscape", COLOR,
"cyan", -1);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, 3, PROGRAM, "Firefox", COLOR,
"yellow", -1);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, 4, PROGRAM, "Calculator", COLOR,
"cyan", -1);
gtk_list_store_append(store, &iter);
gtk_list_store_set(store, &iter, ID, 5, PROGRAM, "Devhelp", COLOR,
"yellow", -1);
GtkWidget *tree=gtk_tree_view_new_with_model(GTK_TREE_MODEL(store));
gtk_widget_set_name(tree, "tree_select");
gtk_widget_set_hexpand(tree, TRUE);
gtk_widget_set_vexpand(tree, FALSE);
GtkCellRenderer *renderer1=gtk_cell_renderer_text_new();
g_object_set(renderer1, "editable", FALSE, NULL);
//Bind the COLOR column to the "cell-background" property.
GtkTreeViewColumn *column1 =
gtk_tree_view_column_new_with_attributes("ID", renderer1, "text", ID,
"cell-background", COLOR, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column1);
GtkTreeViewColumn *column2 =
gtk_tree_view_column_new_with_attributes("Program", renderer1, "text",
PROGRAM, "cell-background", COLOR, NULL);
gtk_tree_view_append_column(GTK_TREE_VIEW(tree), column2);
GtkWidget *grid=gtk_grid_new();
gtk_grid_attach(GTK_GRID(grid), tree, 0, 0, 1, 1);
gtk_container_add(GTK_CONTAINER(window), grid);
GError *css_error=NULL;
gchar css_string[]="#main_window{background: purple;}
#tree_select:selected{background: green;}";
GtkCssProvider *provider = gtk_css_provider_new();
GdkDisplay *display = gdk_display_get_default();
GdkScreen *screen = gdk_display_get_default_screen(display);
gtk_style_context_add_provider_for_screen(screen,
GTK_STYLE_PROVIDER(provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
gtk_css_provider_load_from_data(provider, css_string, -1, &css_error);
if(css_error!=NULL) g_print("CSS loader error %s\n",
css_error->message);
g_object_unref(provider);
gtk_widget_show_all(window);
gtk_main();
return 0;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]