【问题标题】:How to add keybindings to a gtk3 application?如何将键绑定添加到 gtk3 应用程序?
【发布时间】:2013-01-10 01:08:17
【问题描述】:

我正在尝试通过 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;
}

颜色设置有效,因此不能完全破坏。但是没有一个键绑定工作。我错过了什么?

【问题讨论】:

  • 缺少一个破折号:它是-gtk-key-bindings 而不是gtk-key-bindings

标签: css c gtk3


【解决方案1】:

如果我错了,请原谅我,但我相信你把分号放在了错误的地方:)

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

【讨论】:

    【解决方案2】:

    它对我有用:

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

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

    备注:

    • 要使用正确的选择器,您始终可以使用检查器:使用GTK_DEBUG=interactive 启动您的应用程序

    【讨论】:

      猜你喜欢
      • 2017-03-08
      • 2014-10-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2010-11-25
      • 2018-11-02
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多