0

I'm new in the gtk's world and I cannot find a solution to this little problem.

I have this button : button2

But I would like that the small shadow behind the button can be removed. I'd like this result : button2

How can I solve it?

Button's code:

sum_button = gtk_button_new_from_stock(GTK_STOCK_ADD);
/**/
style = gtk_widget_get_style(sum_button);
style->bg[GTK_STATE_PRELIGHT] = style->bg[GTK_STATE_NORMAL];
gtk_widget_set_style(sum_button, style);
/**/
gtk_widget_modify_bg(sum_button, GTK_STATE_NORMAL, &color2);
gtk_button_set_relief(GTK_BUTTON(sum_button), GTK_RELIEF_HALF);
g_signal_connect(G_OBJECT(sum_button), "clicked", G_CALLBACK(PrintNumber),&t_data);
gtk_box_pack_start(GTK_BOX (hbox3), sum_button, TRUE, TRUE, 0);
Marco Rossi
  • 671
  • 1
  • 7
  • 14

2 Answers2

3

Try

gtk_button_set_relief(GTK_BUTTON(sum_button), GTK_RELIEF_NONE);

But then you can not set the background color:

When the button's border relief is set to none, it acts like a label as in it is "transparent", it has the same bg color as its parent container.

Take a look to this thread: https://stackoverflow.com/a/1709648/1606345

Community
  • 1
  • 1
David Ranieri
  • 39,972
  • 7
  • 52
  • 94
0

If you are writing new code, consider using GTK 3, where you can do this with CSS directly:

GtkCssProvider *provider = gtk_css_provider_new();
gtk_css_provider_load_from_data(provider,
    "button {"
    "  border: 0px;"
    "  background-color: green;"
    "  color: white;"
    "}", -1, &error);
GtkStyleContext *context = gtk_widget_get_style_context(button);
gtk_style_context_add_provider(context, provider,
    GTK_STYLE_PROVIDER_PRIORITY_USER);
ptomato
  • 56,175
  • 13
  • 112
  • 165
  • I started using gtk3. I declared 'error' as **GError** *error; and I tried your code, when I compile 0 errors but seems doesn't do anything. The button doesn't change his style. What could be the problem? – Marco Rossi Jun 02 '16 at 09:28
  • I solved using 'GtkButton' as class in a 'style.css' file loaded with gtk_css_provider_load_from_path() function. But it doesn't work if I want to specific a 'enter_button' class (or id) when 'enter_button' is the name of the GtkButton. Any solutions? – Marco Rossi Jun 02 '16 at 13:57