It might be lack of sleep, but I can’t figure this out.
I have a Label
, and I want its text to be red when it represents an error, and I want it be green when it represent “good to go”.
I found search result for C
and maybe a solution for Python
, but nothing for Rust
.
I tried manually setting the css-classes
property and running queue_draw()
; it didn’t work.
I can have a gtk::Box
or a Frame
that I place where the Label
should go, then declare two Label
s, and use set_child()
to switch between them, but that seems like an ugly solution.
Do you have a solution?
SOLVED:
I have to add a “.” before declaring a CSS “thing” for it to be considered a class.
Ex:
.overlay {
background: rgba(60, 60, 60, 1);
font-size: 25px;
}
instead of:
overlay {
background: rgba(60, 60, 60, 1);
font-size: 25px;)
}
Just use label.add_css_class(), label.remove_css_class() or label.set_css_classes() and make sure to properly load your CSS style sheets,
Source: the comment of [email protected]
@Doods my blog note is not showing up in Lemmy.
I’ve tried this quickly and you can use pango markup (https://docs.gtk.org/Pango/pango_markup.html) to change the text color in the label.
Here is a snippet with a label and a button that changes the text color from blue to red.
Here you can find the snippet: https://blog.libove.org/posts/454ace46-64f1-4f7f-a03f-4183430a8d68/