Making a GtkButton round

℡╲_俬逩灬. 提交于 2019-12-31 03:21:12

问题


How can I make GtkBtton round in shape?


回答1:


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.



回答2:


The accepted answer said:

There is no roundness option in the base set.

Well, there is now!

https://developer.gnome.org/gtk3/stable/GtkButton.html

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

So, e.g.:

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

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

There is an issue though: This only work satisfactorily for buttons that have no expand properties set or are not otherwise manually upsized. I've not figured out whether this can be made to work with GtkButtons having expanded size, as with the enlarged button that I wanted this for, I'm getting rounded corners but with flat regions at the sides. :/ My guess is the devs haven't thought, or cared... about supporting larger buttons having the circular style class. Maybe I'll ask on IRC sometime.

update: That was patched, so the curvature now extends all the way around, instead of having flat segments. You'll still get ovals rather than circles if you get the dimensions non-square, but they'll be curved all the way.



来源:https://stackoverflow.com/questions/4212385/making-a-gtkbutton-round

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!