GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Fri Aug 01, 2014 3:45 am

All times are UTC




Post new topic Reply to topic  [ 5 posts ] 
Author Message
 Post subject: GtkCSSProvider for coloring check buttons inside a treeview
PostPosted: Sun Sep 22, 2013 10:00 am 
Offline
Familiar Face

Joined: Mon Jul 11, 2011 10:24 am
Posts: 15
Hello,

I'd like to set a background color for the check buttons inside a treeview, but only for those with either one of the statuses true or false.
Usually I use a cell data function for changes of font-weight, color etc., so I can apply settings for each cell individually, but since there is no background-color attribute for the toggle renderer, I tried with GtkCSSProvider.
With GtkCSSProvider I indeed managed to change the background-color of check buttons, but only for those outside the treeview, it does not affect the check buttons inside it.
Is there a way to set the background color of the check buttons of a treeview, and only for these, not the others?

Thanks


Top
 Profile  
 
 Post subject: Re: GtkCSSProvider for coloring check buttons inside a treev
PostPosted: Mon Oct 07, 2013 12:04 am 
Offline
Familiar Face

Joined: Wed Jan 30, 2013 8:28 pm
Posts: 20
I made this function on my onw project, I hope that it would help you.
Give it a well formated "css_file" filename ( /path_to_youy_filename ex: /home/style.css )

Code:
void css_style_all(gchar* css_file)
{
    GtkCssProvider* css_provider = gtk_css_provider_new();
    if(!gtk_css_provider_load_from_path(css_provider, css_file, NULL))
    {
        g_object_unref(css_provider);
        return;
    }
    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(css_provider), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);
}


Top
 Profile  
 
 Post subject: Re: GtkCSSProvider for coloring check buttons inside a treev
PostPosted: Wed Dec 25, 2013 11:19 pm 
Offline
Familiar Face

Joined: Mon Jul 11, 2011 10:24 am
Posts: 15
My question is not how to use GtkCSSProvider in general (I know how to parse the settings, as it can be done for example according to your code), it is specifically about how to set the background color of buttons inside a treeview, and not all of them, but separately.
This is possible for example for the background- and foreground color of a cell text via g_object_set, using a cell data function, but I don't know how to do this for buttons inside a treeview.

Code:
gtk_css_provider_load_from_data (provider, "GtkButton{\n"
    " background-color: yellow;\n"
    "}\n", -1, NULL);


affects the buttons inside the current window, but not those inside a treeview. I'd like to have it the other way round.

I'Ve also seen the section about regions inside the documentation, but for GtkTreeView these are only defined for rows, columns and column headers, not for widgets placed inside cells.


Top
 Profile  
 
 Post subject: Re: GtkCSSProvider for coloring check buttons inside a treev
PostPosted: Thu Dec 26, 2013 10:00 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 734
Location: UK
Hello,

The objects drawn in a GtkTreeView are not Widgets they are based on the GtkCellRenderer. So any CSS styling that is done on a Widget will not apply to a Cell-Renderer within a GtkTreeView.

The cell renderer for a check box is GtkCellRendererToggle and its parent is GtkCellRenderer which has the properties "cell-background" and "cell-background-rgba" which you could use to set the background colour. You then then use the cell data function to set for individual cells.

_________________
E.


Top
 Profile  
 
 Post subject: Re: GtkCSSProvider for coloring check buttons inside a treev
PostPosted: Thu Dec 26, 2013 1:05 pm 
Offline
Familiar Face

Joined: Mon Jul 11, 2011 10:24 am
Posts: 15
errol wrote:
The objects drawn in a GtkTreeView are not Widgets they are based on the GtkCellRenderer. So any CSS styling that is done on a Widget will not apply to a Cell-Renderer within a GtkTreeView.


OK, I already suspected that, since I can't access them in a way as I can do with widgets.

errol wrote:
The cell renderer for a check box is GtkCellRendererToggle and its parent is GtkCellRenderer which has the properties "cell-background" and "cell-background-rgba" which you could use to set the background colour. You then then use the cell data function to set for individual cells.


I already use cell-background, it does not look perfect when using a button, but I'll leave it then.

Thanks for clarifying things.


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group