Gtk (mm) Change background color of button 3

I am trying to change the background color of a button to red, but it does not seem to work. I am inserting an example code. If anyone can tell me how to fix my code, please help.

#include <gtkmm.h>

// g++ simple.cc -o simple `pkg-config gtkmm-3.0 --cflags --libs`

int  main(int argc, char *argv[])
{
    Gtk::Main kit(argc, argv);
    Gtk::Window  window;
    Gtk::Button  button("TEST");
    button.override_background_color(Gdk::RGBA("red"));
    window.add(button);
    window.show_all();
    Gtk::Main::run(window);
    return EXIT_SUCCESS;
}

UPDATE: OK, as I decided:

mr_screen = Gdk::Screen::get_default();
mr_style_context = mp_window->get_style_context();
mr_css_provider = Gtk::CssProvider::create();
mr_css_provider->load_from_path(Glib::build_filename(m_glade_dir_path, "filename.css"));
mr_style_context->add_provider_for_screen(mr_screen, mr_css_provider, GTK_STYLE_PROVIDER_PRIORITY_USER);

and the contents of the file filename.css:

column-header .button {
    background-image: -gtk-gradient (linear,
        left top,
        left bottom,
        from (#51cccc),
        color-stop (0.5, darker (#51cccc)),
        to (#51cccc));
}
+5
source share
1 answer

I have no experience with C ++, but I am using python, in python you have to do this:

button.override_background_color(Gtk.StateFlags.NORMAL, Gdk.RGBA(1.0 , 0.0 , 0.0, 1.0))

maybe in c ++ you should do it

button.override_background_color(GTK_STATE_FLAGS_NORMAL, Gdk::RGBA(1.0 , 0.0 , 0.0, 1.0));
0
source

All Articles