我使用此代码将图标添加到TreeView列:
def build_tree_view(self):
self.explorer_store = Gtk.TreeStore(Pixbuf, str, str)
icon = Gtk.IconTheme.get_default().load_icon("folder", 22, 0)
for connname, conndata in self.config.get('connections', {}).items():
parent = self.explorer_store.append(None, [icon, connname, self.get_dsn(conndata)])
self.tree_view = Gtk.TreeView(self.explorer_store)
renderer_pixbuf = Gtk.CellRendererPixbuf()
renderer_text = Gtk.CellRendererText()
column1 = Gtk.TreeViewColumn("Column", renderer_text)
column1.pack_start(renderer_text, True)
column1.pack_start(renderer_pixbuf, False)
column1.add_attribute(renderer_pixbuf, "pixbuf", 0)
column1.add_attribute(renderer_text, "text", 1)
self.tree_view.append_column(column1)
我得到了这个结果:
如何将图标对齐文本左侧?
答案 0 :(得分:0)
我找到了解决方案!当我创建一个列时,我不需要将渲染器作为第二个参数传递:
column1 = Gtk.TreeViewColumn("Column", renderer_text)
正确的代码是:
column1 = Gtk.TreeViewColumn("Column")