我需要编写一个定制的Gtk.CellRenderer
(我们称之为CellRendererToogleWithNone
),它的行为类似于Gtk.CellRendererToggle
,但不是只支持True
和False
,我还希望它支持None
,它应该显示为如下不一致状态:
在toggle上,我想按定义的顺序旋转,例如:True->;错误->;没有 (但这可能是最简单的部分,我仍然认为我提到了这一点)
我也不知道如何使它与TreeStore的工作,因为如果我这样做
self.treestore = Gtk.TreeStore.new(types = (bool,))
iter = self.treestore.append(parent = None, row = (None,))
它将任何None
值转换为False
,因为bool
似乎不允许None
值
我在网上找不到任何有用的自定义Gtk.CellRenderer
示例
我想通过从Gtk.CellRenderer
继承而不是从Gtk.CellRendererToggle
继承来实现它,因为这也可以作为一个有用的示例来实现更多这样的单元呈现器
我只能猜测我必须为TreeStore
定义一些自定义数据类型,类似于bool_or_none
而不是bool
(也不知道如何做),并在我的自定义CellRendererToogleWithNone
中保存我自己的Gtk.ToggleButton
编辑0:
This post关于如何编写自定义Gtk.CellRenderer
给出了一些提示,这些提示可能可以重用,但并不能解决我的问题。它没有显示如何使Gtk.TreeStore
接受None
变量的值,我不理解那里的所有内容。它甚至没有使用Gtk.Button,相反,它似乎在一个小部件中画了一个框,我猜这个小部件可能是父部件。我不想绘制自己的切换,我想重用Gtk.ToggleButton
及其inconsistent
属性
编辑1:
因为定制单元渲染器似乎并不容易,所以我认为在python中看到一个最小的工作示例会特别有用。我还应该提到,我希望尽可能简洁地显示数据,这排除了建议的解决方法,例如一个值有两个切换
你被误导了,设置
inconsistant
标志不是Gtk.CellRendererToggle
对象的一部分。已经准备好了。您必须实现Gtk.TreeCellDataFunc
参考文献:
Gtk.TreeViewColumn.set_cell_data_func
Gtk.TreeCellDataFunc
使用Python:3.5-gi进行测试。\u版本:3.22.0
相关问题 更多 >
编程相关推荐