更改 gtk.Paned 手柄大小

发布于 2024-08-11 07:01:28 字数 82 浏览 6 评论 0原文

gtk.Paned 包含一个名为“handle-size”的样式属性,我认为它会更改句柄的大小,它是只读的,那么我该如何更改它?(在 PyGtk 中)

gtk.Paned contains a style property called 'handle-size' which i assume will change the size of the handle, it's read only, so how do i change it?(in PyGtk)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

↙厌世 2024-08-18 07:01:28

来自 gtk.Widget 的文档:

gtk.Widget 引入了样式属性 - 这些基本上是对象属性
不存储在对象上,而是存储在与小部件关联的样式对象中。风格
属性在资源文件中设置。该机制用于配置此类
事物作为滚动条箭头穿过主题的位置,为主题作者提供更多信息
控制应用程序的外观,无需用 C 语言编写主题引擎。

的一般做法是不从程序中设置样式属性,而只是使用标准 UI 小部件并让用户决定它们的外观(通过桌面主题的意思)。

From the documentation for gtk.Widget:

gtk.Widget introduces style properties - these are basically object properties that are
stored not on the object, but in the style object associated to the widget. Style
properties are set in resource files. This mechanism is used for configuring such
things as the location of the scrollbar arrows through the theme, giving theme authors more
control over the look of applications without the need to write a theme engine in C.

The general practice in GTK is not to set style properties from your program, but just use the standard UI widgets and let the user decide how they should look (by means of a desktop theme).

巡山小妖精 2024-08-18 07:01:28

您可以在启动自己的应用程序之前提供自定义资源文件。在 C 语言中(希望 Python 的翻译是简单的),这将是:

#include <gtk/gtk.h>

int
main(gint argc, gchar **argv)
{
    GtkWidget *window;
    GtkPaned  *paned;

    gtk_init(&argc, &argv);

    gtk_rc_parse_string("style 'my_style' {\n"
                        "    GtkPaned::handle-size = 200\n"
                        " }\n"
                        "widget '*' style 'my_style'");

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    paned = (GtkPaned *) gtk_hpaned_new();
    gtk_paned_add1(paned, gtk_label_new("left"));
    gtk_paned_add2(paned, gtk_label_new("right"));

    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(paned));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}

You can feed a custom resource file before starting your own application. In C (hopefully the translation to python is straightforward) that would be:

#include <gtk/gtk.h>

int
main(gint argc, gchar **argv)
{
    GtkWidget *window;
    GtkPaned  *paned;

    gtk_init(&argc, &argv);

    gtk_rc_parse_string("style 'my_style' {\n"
                        "    GtkPaned::handle-size = 200\n"
                        " }\n"
                        "widget '*' style 'my_style'");

    window = gtk_window_new(GTK_WINDOW_TOPLEVEL);

    paned = (GtkPaned *) gtk_hpaned_new();
    gtk_paned_add1(paned, gtk_label_new("left"));
    gtk_paned_add2(paned, gtk_label_new("right"));

    gtk_container_add(GTK_CONTAINER(window), GTK_WIDGET(paned));

    gtk_widget_show_all(window);
    gtk_main();

    return 0;
}
蝶舞 2024-08-18 07:01:28

仅供参考:自 GTK 3.20 起,handle-size 已被弃用

您可以通过 CSS 更改句柄大小:

paned separator{
  background-size:40px;
  min-height: 40px;
}

C 代码

我无法提供 Python 代码,但作为参考,我将发布 C 代码。

void
_paned_change_handle_size(GtkWidget *widget)
{
  GtkStyleContext * context = gtk_widget_get_style_context (widget);

  GtkCssProvider * css = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (css,
                                   "paned separator{"
                                   "background-size:40px;"
                                   "min-height: 40px;"
                                   "}",
                                   -1,NULL);


  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER(css), 
                      GTK_STYLE_PROVIDER_PRIORITY_USER);
}

FYI: handle-size is deprecated since GTK 3.20

You can change the handle size via CSS:

paned separator{
  background-size:40px;
  min-height: 40px;
}

C Code

I can't provide Python code, but for reference I'll post C code.

void
_paned_change_handle_size(GtkWidget *widget)
{
  GtkStyleContext * context = gtk_widget_get_style_context (widget);

  GtkCssProvider * css = gtk_css_provider_new ();
  gtk_css_provider_load_from_data (css,
                                   "paned separator{"
                                   "background-size:40px;"
                                   "min-height: 40px;"
                                   "}",
                                   -1,NULL);


  gtk_style_context_add_provider (context, GTK_STYLE_PROVIDER(css), 
                      GTK_STYLE_PROVIDER_PRIORITY_USER);
}
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文