<p>选择一个项后立即结束对CellRendererCombo的编辑是一个两阶段的过程。在</p>
<p>在第一个阶段,必须捕获组合体本身,因为以后无法访问它。要捕获组合,请连接到<code>editing-started</code>CellRenderer信号。您可以在Glade中定义连接,也可以在代码中手动创建。在</p>
<p>在第二阶段,在cellRenderCombo的<code>changed</code>信号处理程序中发出<code>focus-out-event</code>。在</p>
<p>以下是修改后的原始代码以演示:</p>
<pre><code>comboEditable = None
crc = gtk.CellRendererCombo()
crc.set_property('model', comboModel)
crc.set_property('text-column', 0)
crc.set_property('editable', True)
crc.set_property('has_entry', False)
cl = gtk.TreeViewColumn(ctitle, crc, text=i)
def changed(cell, path, newiter):
treeViewModel[path][0] = "HAH"
e = gtk.gdk.Event(gtk.gdk.FOCUS_CHANGE)
e.window = treeView.window
e.send_event = True
e.in_ = False
comboEditable.emit('focus-out-event', e)
def started(cell, editable, path):
# Or to make life more predictable, use a class and set self.comboEditable
global comboEditable
comboEditable = editable
crc.connect('changed', changed)
crc.connect('editing-started', started)
treeView.append_column(cl)
</code></pre>
<p>注意,在GTK+的较新版本中,通常不会修改<code>changed</code>信号处理程序中的TreeModel。您应该使用<code>edited</code>信号处理程序。在</p>
<p>以下是最终版本:</p>
^{pr2}$