How to change GTK+3 label color dynamically
Hi, Now i need to change GtkLabel color dinamically, so i thing that i can't use Css to do this.. I do this in Gtk2: gtk_widget_modify_fg(GTK_WIDGET(gtk_builder_get_object(builder,"label")),GTK_STATE_NORMAL, ); How can i change the color in Gtk3? Thanks ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list
Re: gtk3 layout background image
Hi again, I tested with GtkBox and don't works.. My code is correct? GFile *file= g_file_new_for_path("custom.css"); GtkStyleProvider *css_provider = GTK_STYLE_PROVIDER(gtk_css_provider_new()); gtk_css_provider_load_from_file(GTK_CSS_PROVIDER(css_provider), file, ); gtk_style_context_reset_widgets(gdk_screen_get_default()); custom.css: GtkBox#Home_PrincipalScreen_table.background{ background-image: url('background.png'); } GtkLabel#Home_Cooling_Tunnel1_Cooler_label1{ color: white; } GtkLabel#Home_Sensors_MoistAvg_value{ font-family: Segoe UI; font-weight: lighter; font-size: 25px; } Thanks On 14-03-2017 14:46, Emmanuele Bassi wrote: > On 14 March 2017 at 14:31, Rúben Rodrigueswrote: >> Just window can have background? > I was referring to GdkWindow, not GtkWindow. > > GtkBox draws background, for instance; GtkGrid does as well. > >> I don't know why is a violation, because in my case my >> applicationdoesn't make sense without background image.. > I think the issue, here, is that you're not aware that 15 years passed > in the internals of GTK+. > > Changing the background pixmap of a GdkWindow is a layering violation > because it assumes that you're essentially working on X11 and you > control the X server as well; on X11, you're telling the X server to > clear the contents of the native window used by GtkLayout using the > bytes you're passing. This worked in 1997, but it's not how modern > toolkits work — and it's not even how different windowing systems > work. Widgets do not have their own native window for rendering any > more, for instance. > > If your application window has a background image then use the > background-image CSS property on your GtkWindow widget. > > Ciao, > Emmanuele. > >> On 14-03-2017 14:01, Emmanuele Bassi wrote: >>> You were not changing the background with your theme: you were >>> programmatically replacing the base pixmap of the GdkWindow used by >>> GtkLayout. It was essentially a layering violation, and would actually >>> break your theme. >>> >>> The API reference for each GTK widget should tell you the CSS styling >>> available; see the "CSS nodes" section, for instance, of GtkBox: >>> https://developer.gnome.org/gtk3/stable/GtkBox.html >>> >>> Ciao, >>>Emmanuele. >>> >>> >>> On 14 March 2017 at 13:55, Rúben Rodrigues wrote: Thanks! But in GTK+2 we could change background in layout with this: // Set picture as background. //gdk_pixbuf_render_pixmap_and_mask (pixbuf, , NULL, 0); //style = gtk_style_new (); //style->bg_pixmap[0] = background; //homeWindow = GTK_WIDGET(gtk_builder_get_object(builder, "layout_Home")); //gtk_widget_set_style (GTK_WIDGET(homeWindow), GTK_STYLE(style)); How i know witch containers draw background? THanks On 14-03-2017 12:55, Emmanuele Bassi wrote: > Not all GTK containers draw a background, mostly for historical > reasons. This has been true for GTK 1.x, 2.x, and 3.x. > > In particular, GtkLayout does not draw any background with CSS, so you > will need to either subclass GtkLayout, override the GtkWidget::draw > virtual function, and call gtk_render_* functions yourself; or you > will need to put a GtkLayout into a parent container that does draw a > background. You will, of course, need to style the parent container's > background, not the GtkLayout itself. > > Ciao, > Emmanuele. > > > On 14 March 2017 at 12:43, Rúben Rodrigues wrote: >> I verify that i can't use css provider, don't works. >> >> My css file is : >> >> GtkLayout#layout_Home.background{ >> background-image: url('background.png'); >> } >> >> GtkLabel#Home_Cooling_Tunnel1_Cooler_label1{ >> color: white; >> } >> >> GtkLabel#Home_Sensors_MoistAvg_value{ >> font-family: Segoe UI; >> font-weight: lighter; >> font-size: 25px; >> } >> >> And this code: >> >> static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) >> { >> gtk_style_context_add_provider(gtk_widget_get_style_context(widget), >> GTK_STYLE_PROVIDER(provider),G_MAXUINT); >> if(GTK_IS_CONTAINER(widget)) >> gtk_container_forall(GTK_CONTAINER(widget),(GtkCallback) >> apply_css,provider); >> >> } >> >> GFile *file= g_file_new_for_path("custom.css"); >> GtkStyleProvider *css_provider = >> GTK_STYLE_PROVIDER(gtk_css_provider_new()); >> gtk_css_provider_load_from_file(GTK_CSS_PROVIDER(css_provider), file, >> ); >> apply_css(gtk_builder_get_object(builder,"window_Main"),css_provider); >> >> This is the code used in gtk3-demo and don't works for me.. Why >> >> THanks
Re: gtk3 layout background image
Thanks, it works! On 15-03-2017 12:49, mhora...@gmail.com wrote: > You need to give the widget a "name" property - than you can select it > in CSS! > > Best, > Martin > > On Wed, 2017-03-15 at 10:28 +, Rúben Rodrigues wrote: >> Hi, >> >> I see now, that the problem i'm not do in correct mode. I do this: >> >> GtkButton{ >> >> color: blue; >> } >> >> and works. All buttons change to blue color. But when i'm changing a >> specific label or GtkBox to put background i do this: >> >> GtkLabel#label_Avg_Temp_value{ >> color: red; >> font-family: Segoe UI; >> font-size: 25px; >> } >> >> And don't change label_Avg_Temp_value . What is the correct way to >> change a specific widget? >> >> Thanks >> >> >> Às 14:46 de 14/03/2017, Emmanuele Bassi escreveu: >>> On 14 March 2017 at 14:31, Rúben Rodrigues>>> wrote: Just window can have background? >>> I was referring to GdkWindow, not GtkWindow. >>> >>> GtkBox draws background, for instance; GtkGrid does as well. >>> I don't know why is a violation, because in my case my applicationdoesn't make sense without background image.. >>> I think the issue, here, is that you're not aware that 15 years >>> passed >>> in the internals of GTK+. >>> >>> Changing the background pixmap of a GdkWindow is a layering >>> violation >>> because it assumes that you're essentially working on X11 and you >>> control the X server as well; on X11, you're telling the X server >>> to >>> clear the contents of the native window used by GtkLayout using the >>> bytes you're passing. This worked in 1997, but it's not how modern >>> toolkits work — and it's not even how different windowing systems >>> work. Widgets do not have their own native window for rendering any >>> more, for instance. >>> >>> If your application window has a background image then use the >>> background-image CSS property on your GtkWindow widget. >>> >>> Ciao, >>>Emmanuele. >>> On 14-03-2017 14:01, Emmanuele Bassi wrote: > You were not changing the background with your theme: you were > programmatically replacing the base pixmap of the GdkWindow > used by > GtkLayout. It was essentially a layering violation, and would > actually > break your theme. > > The API reference for each GTK widget should tell you the CSS > styling > available; see the "CSS nodes" section, for instance, of > GtkBox: > https://developer.gnome.org/gtk3/stable/GtkBox.html > > Ciao, > Emmanuele. > > > On 14 March 2017 at 13:55, Rúben Rodrigues t> wrote: >> Thanks! >> >> But in GTK+2 we could change background in layout with this: >> >> // Set picture as background. >> //gdk_pixbuf_render_pixmap_and_mask (pixbuf, >> , NULL, 0); >> //style = gtk_style_new (); >> //style->bg_pixmap[0] = background; >> //homeWindow = >> GTK_WIDGET(gtk_builder_get_object(builder, >> "layout_Home")); >> //gtk_widget_set_style (GTK_WIDGET(homeWindow), >> GTK_STYLE(style)); >> >> How i know witch containers draw background? >> >> THanks >> >> >> On 14-03-2017 12:55, Emmanuele Bassi wrote: >>> Not all GTK containers draw a background, mostly for >>> historical >>> reasons. This has been true for GTK 1.x, 2.x, and 3.x. >>> >>> In particular, GtkLayout does not draw any background with >>> CSS, so you >>> will need to either subclass GtkLayout, override the >>> GtkWidget::draw >>> virtual function, and call gtk_render_* functions yourself; >>> or you >>> will need to put a GtkLayout into a parent container that >>> does draw a >>> background. You will, of course, need to style the parent >>> container's >>> background, not the GtkLayout itself. >>> >>> Ciao, >>> Emmanuele. >>> >>> >>> On 14 March 2017 at 12:43, Rúben Rodrigues >> om.pt> wrote: I verify that i can't use css provider, don't works. My css file is : GtkLayout#layout_Home.background{ background-image: url('background.png'); } GtkLabel#Home_Cooling_Tunnel1_Cooler_label1{ color: white; } GtkLabel#Home_Sensors_MoistAvg_value{ font-family: Segoe UI; font-weight: lighter; font-size: 25px; } And this code: static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) { gtk_style_context_add_provider(gtk_widget_get_style_conte xt(widget), GTK_STYLE_PROVIDER(provider),G_MAXUINT); if(GTK_IS_CONTAINER(widget)) gtk_container_forall(GTK_CONTAINER(widget),(G tkCallback)
Re: gtk3 layout background image
Hi, I see now, that the problem i'm not do in correct mode. I do this: GtkButton{ color: blue; } and works. All buttons change to blue color. But when i'm changing a specific label or GtkBox to put background i do this: GtkLabel#label_Avg_Temp_value{ color: red; font-family: Segoe UI; font-size: 25px; } And don't change label_Avg_Temp_value . What is the correct way to change a specific widget? Thanks Às 14:46 de 14/03/2017, Emmanuele Bassi escreveu: > On 14 March 2017 at 14:31, Rúben Rodrigueswrote: >> Just window can have background? > I was referring to GdkWindow, not GtkWindow. > > GtkBox draws background, for instance; GtkGrid does as well. > >> I don't know why is a violation, because in my case my >> applicationdoesn't make sense without background image.. > I think the issue, here, is that you're not aware that 15 years passed > in the internals of GTK+. > > Changing the background pixmap of a GdkWindow is a layering violation > because it assumes that you're essentially working on X11 and you > control the X server as well; on X11, you're telling the X server to > clear the contents of the native window used by GtkLayout using the > bytes you're passing. This worked in 1997, but it's not how modern > toolkits work — and it's not even how different windowing systems > work. Widgets do not have their own native window for rendering any > more, for instance. > > If your application window has a background image then use the > background-image CSS property on your GtkWindow widget. > > Ciao, > Emmanuele. > >> On 14-03-2017 14:01, Emmanuele Bassi wrote: >>> You were not changing the background with your theme: you were >>> programmatically replacing the base pixmap of the GdkWindow used by >>> GtkLayout. It was essentially a layering violation, and would actually >>> break your theme. >>> >>> The API reference for each GTK widget should tell you the CSS styling >>> available; see the "CSS nodes" section, for instance, of GtkBox: >>> https://developer.gnome.org/gtk3/stable/GtkBox.html >>> >>> Ciao, >>>Emmanuele. >>> >>> >>> On 14 March 2017 at 13:55, Rúben Rodrigues wrote: Thanks! But in GTK+2 we could change background in layout with this: // Set picture as background. //gdk_pixbuf_render_pixmap_and_mask (pixbuf, , NULL, 0); //style = gtk_style_new (); //style->bg_pixmap[0] = background; //homeWindow = GTK_WIDGET(gtk_builder_get_object(builder, "layout_Home")); //gtk_widget_set_style (GTK_WIDGET(homeWindow), GTK_STYLE(style)); How i know witch containers draw background? THanks On 14-03-2017 12:55, Emmanuele Bassi wrote: > Not all GTK containers draw a background, mostly for historical > reasons. This has been true for GTK 1.x, 2.x, and 3.x. > > In particular, GtkLayout does not draw any background with CSS, so you > will need to either subclass GtkLayout, override the GtkWidget::draw > virtual function, and call gtk_render_* functions yourself; or you > will need to put a GtkLayout into a parent container that does draw a > background. You will, of course, need to style the parent container's > background, not the GtkLayout itself. > > Ciao, > Emmanuele. > > > On 14 March 2017 at 12:43, Rúben Rodrigues wrote: >> I verify that i can't use css provider, don't works. >> >> My css file is : >> >> GtkLayout#layout_Home.background{ >> background-image: url('background.png'); >> } >> >> GtkLabel#Home_Cooling_Tunnel1_Cooler_label1{ >> color: white; >> } >> >> GtkLabel#Home_Sensors_MoistAvg_value{ >> font-family: Segoe UI; >> font-weight: lighter; >> font-size: 25px; >> } >> >> And this code: >> >> static void apply_css(GtkWidget *widget, GtkStyleProvider *provider) >> { >> gtk_style_context_add_provider(gtk_widget_get_style_context(widget), >> GTK_STYLE_PROVIDER(provider),G_MAXUINT); >> if(GTK_IS_CONTAINER(widget)) >> gtk_container_forall(GTK_CONTAINER(widget),(GtkCallback) >> apply_css,provider); >> >> } >> >> GFile *file= g_file_new_for_path("custom.css"); >> GtkStyleProvider *css_provider = >> GTK_STYLE_PROVIDER(gtk_css_provider_new()); >> gtk_css_provider_load_from_file(GTK_CSS_PROVIDER(css_provider), file, >> ); >> apply_css(gtk_builder_get_object(builder,"window_Main"),css_provider); >> >> This is the code used in gtk3-demo and don't works for me.. Why >> >> THanks >> >> On 14-03-2017 10:00, Rúben Rodrigues wrote: >>> Hi guys, >>> >>> Finnaly i migrate my application to gtk+3. So, now i neet to change some >>> things like image background. I used
Re: How to set initial size of TextView?
Eric Cashon via gtk-app-devel-listwrote: > > > Hi Chris, > > Try getting the font height and base the textview height on that. If you > use the font ascent you might have to pad it a little but it should give > you a consistent value to size your textviews with based on font size. > > OK, thanks (and thanks for the sample code too). I'm surprised that there's no easier way of doing it but if there isn't then that's just the way it is I suppose. -- Chris Green · ___ gtk-app-devel-list mailing list gtk-app-devel-list@gnome.org https://mail.gnome.org/mailman/listinfo/gtk-app-devel-list