如何向gtk3应用程序添加键绑定?

问题描述 投票:5回答:2

我正在尝试通过CSS将键绑定添加到gtk3应用程序。这是我到目前为止所拥有的:

// add style provider
GtkCssProvider *css = gtk_css_provider_new();                               
gtk_style_context_add_provider_for_screen(gdk_screen_get_default(),         
        GTK_STYLE_PROVIDER(css), GTK_STYLE_PROVIDER_PRIORITY_APPLICATION);         
gtk_css_provider_load_from_path(css, "bindings.css", NULL);

这是在上一个代码段中加载的'bindings.css':

@binding-set tree-view-bindings {
    bind "j" { "move-cursor" (display-lines, 1) };
    bind "k" { "move-cursor" (display-lines, -1) };
    bind "slash" { "start-interactive-search" () };
}

GtkTreeView {
    color: #F00;
    gtk-key-bindings: tree-view-bindings;
}

颜色设置有效,因此不能完全损坏。但是,这些键绑定均无效。我想念什么?

css c gtk3
2个回答
0
投票

如果我错了,请原谅我,但我相信您将分号放在错误的位置:)

@binding-set tree-view-bindings { bind "j" { "move-cursor" (display-lines, 1); } bind "k" { "move-cursor" (display-lines, -1); } bind "slash" { "start-interactive-search" (); } }


0
投票

它为我以下工作:

treeview { 
  -gtk-key-bindings: tree-view-bindings;
}

所以GtkTreeView变成treeviewgtk-key-bindings变成-gtk-key-bindings

备注:

  • 要使用适当的选择器,您始终可以使用检查器:使用GTK_DEBUG=interactive启动您的应用程序>
© www.soinside.com 2019 - 2024. All rights reserved.