简体   繁体   中英

decrease padding in GTK3 buttons

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?

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM