GTK+ MenuItem Size Small

主宰稳场 提交于 2019-12-23 05:32:38

问题


On a machine running Windows, the MenuItems are too small for my use case.

Therefore, my question is, "how I may increase the font size of the text "Save", "Load" and "Exit?" "

If not, then how can I increase the padding between the MenuItems?
(without adding more of those line separators as seen between "Load" and "Exit")

Additionally, how may I remove the intermediate variable SubMenu1, if possible?


Cropped Screenshot



Below is a complete source to reproduce:

#include <gtk/gtk.h>

int main (int argc, char *argv[]) {
    gtk_init (&argc, &argv);


    GtkWidget* Window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    GtkWidget* MenuBar = gtk_menu_bar_new();
    GtkWidget* MenuItem_File = gtk_menu_item_new_with_mnemonic("_File");

    GtkWidget* SubMenu1 = gtk_menu_new();

    GtkWidget* Item_Save = gtk_menu_item_new_with_mnemonic("_Save");
    GtkWidget* Item_Load = gtk_menu_item_new_with_mnemonic("_Load");
    GtkWidget* Item_Exit = gtk_menu_item_new_with_mnemonic("_Exit");


    gtk_menu_shell_append(GTK_MENU_SHELL(SubMenu1), Item_Save);
    gtk_menu_shell_append(GTK_MENU_SHELL(SubMenu1), Item_Load);

    gtk_menu_shell_append(GTK_MENU_SHELL(SubMenu1), gtk_separator_menu_item_new());

    gtk_menu_shell_append(GTK_MENU_SHELL(SubMenu1), Item_Exit);


    gtk_menu_item_set_submenu(GTK_MENU_ITEM(MenuItem_File), SubMenu1);
    gtk_menu_shell_append(GTK_MENU_SHELL(MenuBar), MenuItem_File);


    GtkWidget* VerticalBox;

    VerticalBox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);

    gtk_box_pack_start(GTK_BOX(VerticalBox), MenuBar, false, false, 0);
    gtk_container_add(GTK_CONTAINER(Window), VerticalBox);


    gtk_widget_show_all(MenuBar);
    gtk_widget_show(VerticalBox);


    gtk_window_set_default_size(GTK_WINDOW(Window), 950, 600);
    gtk_window_set_position(GTK_WINDOW(Window), GTK_WIN_POS_CENTER);
    gtk_window_set_title(GTK_WINDOW(Window), "My Title");

    gtk_widget_show(Window);


    gtk_main();

    return 0;
}

回答1:


Gtk3's font size control (and other style properties) are delegated to the CSS files. It is generally discouraged to do this in your program (though this is certainly possible - have a look at Gtk3's CSS_provider functions). But normally you would like your program to look 'compatible' with other programs, I suspect.

The reason is that the aspect of your program should be controllable from the outside - be it for reasons of personal taste, or for accessibility. So, if you consider the font style for the menus etc, too small, you can:

  • Choose another 'theme' or style, eg. on the Gnome-Look site
  • Look at the Window manager's preferences for an 'Appearance' setting (as it is called in XFCE. There are similar tools in Gnome, KDE, etc.)
  • Modify the CSS files of the theme you are currently using

Many other visual aspects are controlled from the CSS files: Separation between elements (eg. menuitems), rounding of corners, visual effects, etc etc... but, thanks to the CSS system, you can normally just 'tweak' the items you like.

EDIT: If you want to run the executable on another machine, you'd probably need a window manager to run it under, which makes the above still valid.

There is still another solution (which I mentioned above, first paragraph), which is to change the CSS temporarily using the CSS provider set of Gtk functions. If you really want to code program rigidly, you can use the modify_font method of GtkWidget.



来源:https://stackoverflow.com/questions/41072683/gtk-menuitem-size-small

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