GTK +菜单项大小小 [英] GTK+ MenuItem Size Small

查看:107
本文介绍了GTK +菜单项大小小的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在运行Windows的计算机上,对于我的用例而言,MenuItems太小了.

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?" "

如果没有,那么如何增加MenuItem之间的填充?
(不添加加载"和退出"之间看到的更多的行分隔符)

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")

此外,如果可能的话,如何删除中间变量 SubMenu1 ?

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


裁剪的屏幕截图



以下是完整的复制源:



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;
}

推荐答案

Gtk3的字体大小控件(和其他样式属性)委托给CSS文件.通常不建议在程序中执行此操作(尽管这确实是可能的-请查看Gtk3的CSS_provider函数).但是我怀疑,通常情况下,您希望您的程序看起来与其他程序兼容".

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:

  • 选择其他主题"或样式,例如.在 Gnome-Look网站
  • 查看外观"设置(在XFCE中称为外观"设置)的窗口管理器首选项.Gnome,KDE等中也有类似的工具.
  • 修改您当前正在使用的主题的CSS文件

CSS文件还控制了许多其他视觉方面:元素之间的分隔(例如,菜单项),圆角倒圆,视觉效果等……但是,由于CSS系统的支持,您通常可以调整"您喜欢的项目.

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.

编辑:如果要在另一台计算机上运行该可执行文件,则可能需要一个窗口管理器才能在其下运行该可执行文件,这使得上述内容仍然有效.

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.

这篇关于GTK +菜单项大小小的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆