我正在使用Glade将列表框添加到窗口,然后使用Gtk.jl的GtkBuilder将GUI加载到Julia中。加载列表框时,Julia认为它是GtkContainer小部件而不是列表框(除了一个或两个注释外,Julia包的源代码中似乎不存在该列表框)。我已经搜寻了Gtk.jl源代码,但是什么也找不到(或者对我正在看的东西了解得不够多)。

几个列表框信号起作用,但最重要的一个(“行激活”)不起作用。我真的需要这个信号来发射...这没有实现吗?是否有错误?难道我做错了什么?我是否只需要使用更复杂的GtkTreeView?

注释掉的julia代码行是不会触发的信号(我也不太在意)。根据Gtk文档,“激活”信号用于GtkListboxRow,它是用户需要使用的“行激活”信号,但我无法使其发出...

“列表框Example.glade”:

<?xml version="1.0" encoding="UTF-8"?>
<!-- Generated with glade 3.22.1 -->
<interface>
  <requires lib="gtk+" version="3.20"/>
  <object class="GtkWindow" id="win">
    <property name="can_focus">False</property>
    <child>
      <placeholder/>
    </child>
    <child>
      <object class="GtkListBox" id="lb">
        <property name="visible">True</property>
        <property name="can_focus">False</property>
        <child>
          <object class="GtkListBoxRow">
            <property name="width_request">100</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <child>
              <object class="GtkLabel">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">label1</property>
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkListBoxRow">
            <property name="width_request">100</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <child>
              <object class="GtkLabel">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">label2</property>
              </object>
            </child>
          </object>
        </child>
        <child>
          <object class="GtkListBoxRow">
            <property name="width_request">100</property>
            <property name="height_request">80</property>
            <property name="visible">True</property>
            <property name="can_focus">True</property>
            <child>
              <object class="GtkLabel">
                <property name="visible">True</property>
                <property name="can_focus">False</property>
                <property name="label" translatable="yes">label3</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
  </object>
</interface>
using Gtk

app = GtkBuilder(filename = "listbox Example.glade")

win = app["win"]

lb = app["lb"]

showall(win)

# id1 = signal_connect(lb, "activate-cursor-row") do widget
#     println("activate-cursor-row")
# end

# id2 = signal_connect(lb, "move-cursor") do widget
#     println("move-cursor")
# end

id3 = signal_connect(lb, "row-activated") do widget
    println("row-activated")
end

id4 = signal_connect(lb, "row-selected") do widget
    println("row-selected")
end

id5 = signal_connect(lb, "select-all") do widget
    println("select-all")
end

id6 = signal_connect(lb, "selected-rows-changed") do widget
    println("selected-rows-change")
end

# id7 = signal_connect(lb, "toggle-cursor-row") do widget
#     println("toggle-cursor-row")
# end

id8 = signal_connect(lb, "unselect-all") do widget
    println("unselect-all")
end

# id9 = signal_connect(lb, "activate") do widget
#     println("activate")
# end
julia> typeof(lb)
Gtk.GtkContainerLeaf

最佳答案

每个信号都有自己的一组参数。例如,“selected-rows-changed”仅具有窗口小部件,而“row-activated”具有窗口小部件和行。

https://developer.gnome.org/gtk3/stable/GtkListBox.html#GtkListBox-selected-rows-changed
https://developer.gnome.org/gtk3/stable/GtkListBox.html#GtkListBox-row-activated

您应该更改:

id3 = signal_connect(lb, "row-activated") do widget
    println("row-activated")
end

至:
id3 = signal_connect(lb, "row-activated") do widget, row
    println("row-activated")
end

关于listbox - 当前的Julia Gtk.jl包中未实现GtkListbox吗?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/58152395/

10-11 07:15