Create TextView with transparent background? (original) (raw)
December 6, 2021, 2:13pm 1
Hi,
I want to create a TextView with a transparent background (GTK4)
Currently, I have this:
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:
I’ve also tried gtk_widget_set_opacity(..)
, but it makes the text transparent as well
Is there any way to achieve it? Thanks
matthiasc (Matthias Clasen) December 6, 2021, 4:07pm 2
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:
system (system) Closed January 5, 2022, 7:05pm 5
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.