[英]Glade GTK3 Python treeview toggles wont toggle
I have an application where the GtkCellRendererToggle does not trigger a callback when I use Glade to build the the application. 我有一个应用程序,当我使用Glade构建应用程序时,GtkCellRendererToggle不会触发回调。 Specifically, if the toggle button is set to True when I click on it, the callback is executed, but when the button is toggled to False, the callback is not triggered.
具体来说,如果在我单击切换按钮时将其设置为True,则将执行回调,但是当将按钮切换为False时,不会触发回调。
I am using Python 3, GTK3 and Glade 3.22.1 I am including the Python source code along with the associated xml. 我正在使用Python 3,GTK3和Glade 3.22.1,我包括Python源代码以及相关的xml。 The working example comes from the python gtk3 tutorial: https://python-gtk-3-tutorial.readthedocs.io/en/latest/cellrenderers.html
工作示例来自python gtk3教程: https ://python-gtk-3-tutorial.readthedocs.io/en/latest/cellrenderers.html
Blockquote
块引用
<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>
/> />
Blockquote
块引用
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]
/> />
What you will see is 3 rows of toggle buttons with the first and third checked. 您将看到3排切换按钮,其中第一和第三项处于选中状态。 If you click on one of the checked boxes, the on_cell_toggle callback is executed, but once it has been toggled to false, it no longer triggers the callback.
如果单击复选框中的一个,则将执行on_cell_toggle回调,但是一旦将其切换为false,它将不再触发该回调。 In the example in the tutorial the toggle works as expected.
在本教程的示例中,切换按预期工作。
You have set the activatable property to the same column as active property: 您已将可激活属性设置为与活动属性相同的列:
<attributes>
<attribute name="activatable">0</attribute>
<attribute name="active">0</attribute>
</attributes>
should be: 应该:
<attributes>
<attribute name="active">0</attribute>
</attributes>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.