使用GMenu菜单中的巨大差距 [英] Big gaps in Menu using GMenu

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

问题描述

使用GMenu(Gnome/Gtk)创建菜单时,菜单项的标签(->图片)上留有很大的空隙.有什么想法要解决吗?

When creating a menu using GMenu (Gnome/Gtk) there is a huge gap left to the labels of the menu items(-> Picture). Any thoughts how to fix this?

#include <gio/gio.h>
#include <glib.h>
#include <glib-object.h>
#include <glib/gi18n.h>

//....
//....


if(title && (action || submenu))
{
   GMenuItem *item;

   if(submenu)
   {
      item = g_menu_item_new_submenu (title, G_MENU_MODEL(submenu));
   }
   else
   {
      item = g_menu_item_new(title, action);
      if (icon != NULL)
      {
         g_menu_item_set_attribute (item, "icon", "s", icon);
      }
   }

//.....
//....

图片

推荐答案

不幸的是,这就是预期的方式成为.您可以坚持使用已弃用的 GtkImageMenuItem ,直到将应用程序移植到GTK 4之前,这才是没有问题的.如果您确实想避免使用已弃用的组件,则可以将图像+标签包装在 GtkBox中正如文档中所建议的那样,尽管它不是那么简单,但是还是需要一些怪癖才能得到一个体面的解决方案:

Unfortunately that's the way it's intended to be. You can stick to the deprecated GtkImageMenuItem which is not problem until you port your app to GTK 4. If you really want to avoid deprecated components, it's possible to wrap an image + label in a GtkBox as suggested by the documentation, although it's not so straightforward, there are some needed quirks to get a decent solution:

  1. 您需要在菜单上使用 gtk_menu_set_reserve_toggle_size 并将其设置为 FALSE .
  2. 然后,您需要为每个菜单项创建标签和图像,但是对于没有图标的项,则需要创建将用作填充符的图像,即 gtk_image_new_from_icon_name(",GTK_ICON_SIZE_BUTTON)
  1. You need to use gtk_menu_set_reserve_toggle_size on the menu and set that to FALSE.
  2. Then you need to create the label and image for each menu item, however for items without icons it's necessary to create an image that will act as a filler, i.e. gtk_image_new_from_icon_name ("", GTK_ICON_SIZE_BUTTON)

您可以在此处找到完整的示例.

You can find a fully working sample here.

注意:不能保证这可以在GTK 4上正常工作.

Note: there is no guarantee this will properly work on GTK 4.

这篇关于使用GMenu菜单中的巨大差距的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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