Creating columns with editable cells in Gtk treeview using Glade
Asked Answered
D

3

9

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

Dogs answered 29/6, 2010 at 17:40 Comment(2)
UI and model are not connected. This repo could help you gitlab.gnome.org/albfan/gtktreeview-exampleToombs
The repo seems to be privateBritten
D
6

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
Dogs answered 2/7, 2010 at 9:48 Comment(0)
L
1

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

Lamented answered 12/2, 2021 at 21:3 Comment(0)
F
0

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)
Frankiefrankincense answered 21/10, 2012 at 20:35 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.