开发者

Creating columns with editable cells in Gtk treeview using Glade

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.开发者_C百科 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


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


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)


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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜