-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Need example of how to set color of an individual widget/button in Gtk4.jl #56
Comments
To style individual widgets you can set classes in the CSS file and then apply them to the widgets. This functionality is surprisingly poorly documented, I learned about it from here: https://stackoverflow.com/questions/72911291/vala-how-to-set-color-of-gtk4-label-programatically Here's an example: using Gtk4
# in CSS, define classes for the styles you want:
css="""
.red {
background: red;
color: white;
}
.blue {
background: blue;
color: white;
}
"""
win=GtkWindow("styling individual widgets")
cssprov=GtkCssProvider(css)
push!(Gtk4.display(win), cssprov) # applies the CSS to all widgets
b=GtkBox(:v)
red_button = GtkButton("I'm red")
blue_button = GtkButton("I'm blue")
push!(b,red_button)
push!(b,blue_button)
win[]=b
# add the CSS classes to the widgets (you can add more than one)
add_css_class(red_button,"red")
add_css_class(blue_button,"blue")
# CSS classes can be removed with `remove_css_class` This should be what you need. PR's of new examples and documentation are welcome! |
Thank you so much! I will leave this open until I make a PR. |
Closed by #57 |
The Gkt4 docs are super helpful, but right now the do not seem to mention how to set the color of an individual widget (like a button) or other style attributes like font color and font size.
The only hint I can find is the CSS example:
https://github.com/JuliaGtk/Gtk4.jl/blob/main/examples/css.jl
That example sets the button color (and font style) for the entire window, leaving open the question of how to control those attributes separately for each individual widget.
(My students need black and white keys for a piano.)
In Gtk3 it was like this:
If someone (maybe @jwahlstrand?) explains how to do this in Gtk4 then I will make a PR for another example akin to css.jl to help others. Thanks!
The text was updated successfully, but these errors were encountered: