使用 Glade 在 Gtk 树视图中创建具有可编辑单元格的列

发布于 2024-09-07 03:55:06 字数 301 浏览 5 评论 0原文

我正在尝试创建一个简单的 GUI,其中包含样本的 x 和 y 坐标表。我使用树视图,我希望用户可以编辑表格的单元格。是否可以指定单元格是否可以直接在 Glade 的 cellrenderer 属性中进行编辑,还是必须在代码中指定?我使用 Glade 3.6.1

我刚刚发现在编辑树视图时取消勾选树视图编辑器中的“可编辑”框,使我能够指定单元格是否可编辑,因为如果取消勾选该框,则单元格可编辑属性不再与模型相关。 但是,如果我运行该程序,单元格是可编辑的,但我在其中写入的值会消失。我该如何解决这个问题?为什么单元格不存储我在其中输入的值?

感谢您的任何提示

I am trying to create a simple GUI with table containing x and y coordinates of samples. I use treeview, and I want the cells of the table to be editable by user. Is it possible to specify if the cells should be editable directly in Glade in cellrenderer properties, or do I have to specify it in my code? I use Glade 3.6.1

I have just found out that unticking box "Editable" in the Tree View Editor when editing my treeview, enables me to specify whether the cells shall be editable or not, because if the box is unticked, the cells editable property is no longer connected with the model.
But if I run the program, cells are editable, but the value that I write inside disappears. How can I fix that? Why doesn't the cell store the value I type inside?

Thanks for any hint

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

西瓜 2024-09-14 03:55:06

对于处理类似问题的任何人,我已经解决了它 - 每当编辑单元格时,都需要更改模型中的适当记录,Python 中的示例代码:

cell.connect("edited", self.text_edited, model, column)

def text_edited( self, w, row, new_text, model, column)
  model[row][column] = new_text

For anyone dealing with a similar problem, I have solved it - whenever a cell is edited, appropriate record in the model needs to be changed, example code in Python:

cell.connect("edited", self.text_edited, model, column)

def text_edited( self, w, row, new_text, model, column)
  model[row][column] = new_text
夜唯美灬不弃 2024-09-14 03:55:06

对于 python GTK,默认情况下,Gtk.CellRendererText 小部件中的文本不可编辑,您可以通过将“editable”属性的值设置为 True 来更改此设置:

renderer = Gtk.CellRendererText();
renderer.set_property("editable", True);

然后您可以连接到“edited”信号并更新您的 Gtk.TreeModel和/或相应的数据库:

renderer.connect("edited", self.entry_edited);

def entry_edited(self, widget, path, text):
    self.listStore[path][number_of_row] = text;  # put the number_of_row to be edited

查看本教程以获取更多信息 python gtk 3 教程 - CellRendererText

for python GTK, by default, text in Gtk.CellRendererText widgets is not editable, you can change this by setting the value of the “editable” property to True:

renderer = Gtk.CellRendererText();
renderer.set_property("editable", True);

then you can connect to the “edited” signal and update your Gtk.TreeModel and/or database accordingly:

renderer.connect("edited", self.entry_edited);

def entry_edited(self, widget, path, text):
    self.listStore[path][number_of_row] = text;  # put the number_of_row to be edited

check this tutorial for more information python gtk 3 tutorial - CellRendererText

奈何桥上唱咆哮 2024-09-14 03:55:06

我发现我必须做一些稍微不同的事情,但我也在使用 Ubuntu 的 Quickly 开发环境。我确实必须进入 Glade 并取消选中 cellrenderer 中的“可编辑”框,然后弹出一个可切换的“是/否”按钮。然后我的代码如下所示:

#psuedo-code function definition
cellcolumn_widget.connect("edited", self.function, list_or_treestore, columnnumber)

#actual code, editing second column so column is passed as 1
self.builder.get_object("cellrenderer_chapter").connect("edited", self.cell_edited, self.builder.get_object("liststore_chapters"),1)

def cell_edited(self, widget, row, new_text, model, column):
    model.set_value(model.get_iter(row),column,new_text)

I found I had to do something just a little different, but I am also using Ubuntu's Quickly development environment. I did have to go into Glade and uncheck the "Editable" box in my cellrenderer, which then brought up a toggable "Yes/No" button. Then my code looks like:

#psuedo-code function definition
cellcolumn_widget.connect("edited", self.function, list_or_treestore, columnnumber)

#actual code, editing second column so column is passed as 1
self.builder.get_object("cellrenderer_chapter").connect("edited", self.cell_edited, self.builder.get_object("liststore_chapters"),1)

def cell_edited(self, widget, row, new_text, model, column):
    model.set_value(model.get_iter(row),column,new_text)
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文