看at the tutorial,有一个示例将两个单元格渲染器打包到一列。不同之处在于您使用的是自定义树模型,而行为取决于您建模模型的方式。如果你有一列是文本,一列是 pixbuf,你可以使用set_attributes:
column = gtk.TreeViewColumn('Pixbuf and text')
cell1 = gtk.CellRenderText()
cell2 = gtk.CellRenderPixbuf()
column.pack_start(cell1, True)
column.pack_start(cell2, False)
column.set_attribute(cell1, 'text', 0) # the first column contains the text
column.set_attribute(cell2, 'pixbuf', 1) # the second column contains the pixbuf
否则你可以拥有一个只有一列的树模型,其中包含你需要的所有对象,所以只需设置一个回调:
class MyObject:
def __init__(self, text, pixbuf):
self.text = text
self.pixbuf = pixbuf
def cell1_cb(col, cell, model, iter):
obj = model.get_value(iter)
cell.set_property('text', obj.text)
def cell2_cb(col, cell, model, iter):
obj = model.get_value(iter)
cell.set_property('pixbuf', obj.pixbuf)
column = gtk.TreeViewColumn('Pixbuf and text')
cell1 = gtk.CellRenderText()
cell2 = gtk.CellRenderPixbuf()
column.pack_start(cell1, True)
column.pack_start(cell2, False)
column.set_cell_data_func(cell1, cell1_cb)
column.set_cell_data_func(cell2, cell2_cb)
我希望我能给你一个关于你可以做什么的想法和一个起点。免责声明:我没有测试代码。