Create TextView with transparent background?

,

Hi,
I want to create a TextView with a transparent background (GTK4)

Currently, I have this:
Screenshot from 2021-12-06 14-53-10

I’ve tried applying a CSS style using the following code:

GtkCssProvider* provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(	provider,
										"textview text { background-color: rgba(1.0, 1.0, 1.0, 0.5); }",
										-1);
gtk_style_context_add_provider(	gtk_widget_get_style_context(textview),
									GTK_STYLE_PROVIDER(provider),
									GTK_STYLE_PROVIDER_PRIORITY_USER);

…but it only turns my widget darker:
Screenshot from 2021-12-06 15-03-24

I’ve also tried gtk_widget_set_opacity(..), but it makes the text transparent as well

Is there any way to achieve it? Thanks

Have you tried

background: none

?

I tried it just now, nothing happens

Okay so I randomly figured it out. I don’t know why it works, as I don’t know much about CSS, but it works. Basically I had to set the background transparency twice for some reason:

GtkCssProvider* provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(	provider,
										"textview { background-color: rgba(1, 1, 0, 0.25); } textview text { background-color: rgba(1, 1, 0, 0.25); }",
										-1);
gtk_style_context_add_provider(	gtk_widget_get_style_context(phh),
									GTK_STYLE_PROVIDER(provider),
									GTK_STYLE_PROVIDER_PRIORITY_USER);

This is my result:
Screenshot from 2021-12-06 20-01-59

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.