Thursday, May 23, 2024
2
rated 0 times [  2] [ 0]  / answers: 1 / hits: 735  / 3 Years ago, wed, may 26, 2021, 9:46:08

In PyGI (GTK3), how can I make a GtkEntry widget appear against the same background applied (by the user's theme) to the primary toolbar. I tried adding the same style class like this:



entry.get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)


but that class doesn't seem to be observed on a widget that isn't a GtkToolbar. So how can I cue the user's theme to apply the same styles behind a GtkEntry widget?



(If it matters, I have the GtkEntry in the first cell of a GtkHBox container. But even when I apply a fixed gradient to that HBox the whole cell holding the GtkEntry seems to mask out the background of the HBox with a flat background colour.)



Thanks.


More From » application-development

 Answers
2

It is called primary-toolbar style because it should be applied only to primary toolbar.



In Gtk, toolbars by default can hold only ToolButtons, but there is the ToolItem class, which does not have a visual represntation.



That is created because it can embed other widgets.
ToolItem has add method which you can use like :



my_tool_item.add(my_box)
where my_box contains your entry



Then you can add your tool item to toolbar
my_toolbar.insert(my_tool_item,index)



Your toolbar of course has called :
get_style_context().add_class(Gtk.STYLE_CLASS_PRIMARY_TOOLBAR)



The reason why you cannot use "primary-toolbar" with non Toolbar widgets is most probably because in .css files it is defined like :



GtkToolbar.primary-toolbar 

{

/* style info*/

}

[#36285] Friday, May 28, 2021, 3 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
arsleyeuth

Total Points: 72
Total Questions: 121
Total Answers: 112

Location: North Korea
Member since Mon, Oct 31, 2022
2 Years ago
;