Is it possible to set custom theme in GTK 3 application? (better on gtk-rs)
I know that GIMP has option to choose between system theme and light-gray-dark preinstalled themes, which are (probably) located somewhere in GIMP config folders.
I have already tried to use GTK_THEME
env variable, but the theme is erased to blank.
Ok, I’ve figured it out. Now I know, that GTK theme is just a CSS configuration for GTK elements, so I can use CssProvider component to apply it to my application:
use gtk::{CssProvider, StyleContext};
use gtk::prelude::*;
pub fn build(application: >k::Application){
let glade_src = include_str!("../../layouts/layout.glade");
let builder = gtk::Builder::from_string(glade_src);
let window: gtk::ApplicationWindow = builder.object("main_window").unwrap();
let provider = CssProvider::new();
provider.load_from_path("themes/Orchis-Orange/Orchis-Orange-Dark/gtk-3.0/gtk.css").unwrap();
let context = window.style_context();
StyleContext::add_provider_for_screen(&gdk::Screen::default().unwrap(), &provider, gtk::STYLE_PROVIDER_PRIORITY_APPLICATION);
window.set_application(Some(application));
window.maximize();
window.show_all();
}
fn main() {
let application = gtk::Application::builder()
.application_id("org.example.application")
.build();
application.connect_activate(build);
application.run();
}
This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.