PyGTK:双击 CellRenderer
在我的 PyGTK 应用程序中,我目前使用“可编辑”来使单元格可编辑。但由于我的单元格内容有时非常大,我想在用户双击单元格时要求用户在新窗口中进行更改。但我不知道如何挂钩特定单元格渲染器上的双击 - 我不想编辑整行,也不想为整行设置此回调,仅针对内容太长的列可能会发生。我如何使用 CellRendererText() 或类似的东西来做到这一点。
我当前的单元格生成代码是:
cols[i] = gtk.TreeViewColumn(coltitle)
cells[i] = gtk.CellRendererText()
cols[i].pack_start(cells[i])
cols[i].add_attribute(cells[i], 'text', i)
cols[i].set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
cols[i].set_fixed_width(100)
cells[i].set_property('editable', True)
cells[i].connect('edited', self.edited, (i, ls))
cols[i].set_resizable(True)
mytreeview.append_column(cols[i])
谢谢!
In my PyGTK application I currently use 'editable' to make cells editable. But since my cell contents sometimes are really really large I want to ask the user for changes in a new window when he doubleclicks on a cell. But I could not find out how to hook on double-clicks on specific cellrenderers - I don't want to edit the whole row and I also don't want to set this callback for the whole row, only for columns where too long content can occur. How can I do this with CellRendererText() or something similar.
My currently cell-generating code is:
cols[i] = gtk.TreeViewColumn(coltitle)
cells[i] = gtk.CellRendererText()
cols[i].pack_start(cells[i])
cols[i].add_attribute(cells[i], 'text', i)
cols[i].set_sizing(gtk.TREE_VIEW_COLUMN_FIXED)
cols[i].set_fixed_width(100)
cells[i].set_property('editable', True)
cells[i].connect('edited', self.edited, (i, ls))
cols[i].set_resizable(True)
mytreeview.append_column(cols[i])
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我相信这是不可能直接实现的。但是,您可以连接到
gtk.TreeView
上的button-press-event
。然后,当event.type
等于gtk.gdk._2BUTTON_PRESS
时,使用以下命令将x
和y
转换为树位置gtk.TreeView.get_path_at_pos()
。这将返回指示行的树路径和单击的 gtk.TreeViewColumn 对象。I believe this is not possible directly. However, you can connect to
button-press-event
on thegtk.TreeView
. Then, whenevent.type
equals togtk.gdk._2BUTTON_PRESS
, convertx
andy
to tree location usinggtk.TreeView.get_path_at_pos()
. This will return both a tree path indicating the row andgtk.TreeViewColumn
object on which the click was made.