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 Oct 24, 2014 8:33 pm

All times are UTC




Post new topic Reply to topic  [ 10 posts ] 
Author Message
 Post subject: Widget color int GTK3
PostPosted: Mon Nov 18, 2013 12:04 pm 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Hello, everyone!

Is it normal that colors of a widget (GtkTextEntry for example) from GTK-theme superseeds the color that I set manually with gtk_widget_modify_base?


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Tue Nov 19, 2013 8:50 am 
Offline
Never Seen the Sunlight

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

gtk_widget_modify_base() has been deprecated since GTK+ v3.0 was introduced. You should now use gtk_widget_override_background_color() instead.

A GtkEntry does not has a GDK window and as such does not have a background that can be set. There are many other widgets that do not have a GDK window. This is done to improve drawing and speed. Their background colour will be taken from the container or the containers container until it gets to a widget that has a GDK window.

https://developer.gnome.org/gtk3/stable/chap-drawing-model.html explains more about the way GTK draws widgets.

_________________
E.


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Tue Nov 19, 2013 3:12 pm 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
errol wrote:
gtk_widget_modify_base() has been deprecated since GTK+ v3.0 was introduced. You should now use gtk_widget_override_background_color() instead.

A GtkEntry does not has a GDK window and as such does not have a background that can be set. There are many other widgets that do not have a GDK window. This is done to improve drawing and speed. Their background colour will be taken from the container or the containers container until it gets to a widget that has a GDK window.
...

Thank you for information, errol!
Now I use gtk_widget_override_background_color() for GtkTextView in GTK3 and gtk_widget_get_has_window(my_text_view) returns true, but... my GkTextView doesn't change color any way :( In Windows without installed gtk-theme it works, in linux with installed gtk-theme it doesn't.Why?


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Thu Nov 21, 2013 8:21 am 
Offline
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 764
Location: UK
GtkTextView has a foreground colour. This maybe a transparent colour in some themes. You will then use the API function gtk_widget_override_color(). There is a sample bit of code in the documentation which shows its use at https://developer.gnome.org/gtk3/stable/TextWidget.html

_________________
E.


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Wed Dec 18, 2013 4:47 am 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
What GTK version and Linux theme are you using?

Did you see the code I posted in the tutorials section:
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195276=Styling+a+GtkTextView+with+Gtk3+and+Css#p195276


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Wed Dec 18, 2013 5:51 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
uname -a: Linux ubuntu 3.2.0-29-generic #46-Ubuntu SMP Fri Jul 27 17:03:23 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux Unity
pkg-config gtk+-3.0 --modversion: 3.4.2
theme: Adwaita or Albatrose or none

Which part of that tutorial could help me with color of GtkEntry?


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Wed Dec 25, 2013 8:05 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
Sorry I was confused by your original question. There's no such widget as GtkTextEntry. There's a GtkTextView and a GtkEntry.
The Window Manager has the final say in how anything will appear on-screen. But depending on your Linux version and if your using Unity you may have to use different CSS.
For instance, if your using Ubuntu 12.04 use background instead of background-color

Or you might to need to add a new class using: gtk_style_context_add_class
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195488=Status+Icons#p195488

Both methods have been reported to work.
http://askubuntu.com/questions/158137/problem-with-theming-my-application-with-css


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Thu Dec 26, 2013 5:11 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Quote:
The Window Manager has the final say in how anything will appear on-screen. But depending on your Linux version and if your using Unity you may have to use different CSS.
For instance, if your using Ubuntu 12.04 use background instead of background-color

OK, it really works, but I don't want to change appearance of all GtkEntry on my screen, I just want to change color of particular GtkEntry. For example my window contains entry1, entry 2 and entry3 and I need to set background color of entry1 as gray, entry2 as white and entry3 as blue. How can I get it without external files? And why can I simply use gtk_widget_override_background_color for GtkTextView, but I can't do the same for GtkEntry in GTK+ 3.0 in Linux?!


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Thu Dec 26, 2013 8:49 pm 
Offline
GTK+ Guru

Joined: Fri Mar 25, 2011 5:16 pm
Posts: 177
Location: USA
To target a particular widget you need to first name it using: gtk_widget_set_name.
Then in the CSS, precede the name of the widget with # which is called the ID selector in CSS.
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195487=Status+Icon+Part+3#p195487

You can use internal CSS by using: gtk_css_provider_load_from_data
http://www.gtkforums.com/viewtopic.php?f=3&t=988&p=195278=GTK3+with+CSS%3A+Background+images#p195278

As far as why can you use gtk_widget_override_background_color for GtkTextView, but not with GtkEntry. I couldn't tell you. That's a question for the GTK developers.


Top
 Profile  
 
 Post subject: Re: Widget color int GTK3
PostPosted: Fri Dec 27, 2013 4:04 am 
Offline
GTK+ Guru

Joined: Tue Feb 05, 2008 8:39 am
Posts: 130
Thank you very much for your answer, zerohour! Is there any possibility to change the data, from which css provider was created, ater that?


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

All times are UTC


Who is online

Users browsing this forum: No registered users and 1 guest


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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group