Question

Since the last update pack of Linux Mint Debian, GTK3 buttons suddenly need more width than before, so that they don't fit in an application I wrote. The problem is that they allocate more space around the button label (something like 25 pixels each side), and cannot be convinced not to do so.

The button was created with gtk_button_new_with_label, so nothing fancy.

I tried everything to reduce that wasted space, but nothing worked:

gtk_widget_set_size_request(GTK_WIDGET(mybutton),1,1);    does nothing.
gtk_widget_set_margin_right(sidebar.button[i],0);         decreases the spacing around the button, not inside.
gtk_container_set_border_width(GTK_CONTAINER(mybutton),0); decreases the spacing around the button, not inside.

what have I missed?

Was it helpful?

Solution

I guess that's defined in the stylesheet of the theme you are using. You can try overriding the style of the widget using GtkCssProvider. A python example could look something like

my_style_provider = Gtk.CssProvider()
my_style_provider.load_from_data(b'GtkWidget { padding-left: 0; padding-right: 0; }')
context = widget.get_style_context()
context.add_provider(my_style_provider, Gtk.STYLE_PROVIDER_PRIORITY_APPLICATION)

Note: untested.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top