Glade GTK3 Python树视图切换不会切换

问题描述 投票:1回答:1

我有一个应用程序,当我使用Glade构建应用程序时,GtkCellRendererToggle不会触发回调。具体来说,如果单击它时切换按钮设置为True,则执行回调,但是当按钮切换为False时,不会触发回调。

我正在使用Python 3,GTK3和Glade 3.22.1我包含了Python源代码以及相关的xml。工作示例来自python gtk3教程:https://python-gtk-3-tutorial.readthedocs.io/en/latest/cellrenderers.html

大段引用

<object class="GtkTreeView" id="treeview">
      <property name="visible">True</property>
      <property name="can_focus">True</property>
      <property name="model">liststore</property>
      <child internal-child="selection">
          <object class="GtkTreeSelection">
              <property name="mode">none</property>
          </object>
      </child>
      <child>
          <object class="GtkTreeViewColumn" id="togglecolumn">
          <property name="title">Togggle</property>
      <child>
          <object class="GtkCellRendererToggle" id="togglerenderer">
              <signal name="toggled" handler="on_cell_toggled" swapped="no"/>
          </object>
              <attributes>
                  <attribute name="activatable">0</attribute>
                  <attribute name="active">0</attribute>
              </attributes>
      </child>
</object>

/>

大段引用

builder = Gtk.Builder()
builder.add_from_file("example.glade")
window = builder.get_object("window")
# Load list data.
self.liststore = builder.get_object ("liststore")

builder.connect_signals(self)
window.show()

def on_cell_toggled(self, widget, path):
    self.liststore[path][0] = not self.liststore[path][0]

/>

你会看到3行切换按钮,第一次和第三次检查。如果单击其中一个复选框,则会执行on_cell_toggle回调,但一旦将其切换为false,它就不再触发回调。在本教程的示例中,切换按预期工作。

python gtk3 glade
1个回答
0
投票

您已将可激活属性设置为与活动属性相同的列:

<attributes>
    <attribute name="activatable">0</attribute>
     <attribute name="active">0</attribute>
</attributes>

应该:

<attributes>
     <attribute name="active">0</attribute>
</attributes>
© www.soinside.com 2019 - 2024. All rights reserved.