boom
boom

Reputation: 6166

Making a GtkButton round

How can I make GtkBtton round in shape?

Upvotes: 4

Views: 3579

Answers (2)

underscore_d
underscore_d

Reputation: 6797

The accepted answer said:

There is no roundness option in the base set.

Well, there is now! See the GTKWidget documentation:

In special cases, buttons can be made round by adding the .circular style class.

So, for example:

gtk_style_context_add_class (gtk_widget_get_style_context (button),
                             "circular");

This works using both of the standard themes, Adwaita and HighContrast.

In GTK4, there are convenience functions to avoid having to get the StyleContext yourself:

gtk_widget_add_css_class (button, "circular");

The above assumebutton is a GtkWidget*. If, instead, it's a GtkButton* or subclass, just substitute in GTK_WIDGET (button) of course.

Upvotes: 5

Rubinium
Rubinium

Reputation: 121

There are a few options.

  • Tweak the style. There is no roundness option in the base set. Some theme engines may provide border image specification or roundness but it will not work everywhere.
  • Force a theme that looks the way you want it too. This is not too hard you just load a gtkrc string that specifies the theme you want. You will need to ensure users have the theme or are ok with the fallback.
  • Subclass the button and draw it yourself. One way is to set border and relief to 0, pack an image, and respond to state change events to use appropriate pre-light (hover) images. Another way is to rewrite the expose event and draw the button as you wish.

Upvotes: 0

Related Questions