How to detect treeview parent and child row on start edit and complete edit


I have a treeview entries like this

Parent 0
|-> Child 0
|-> Child 1
|-> Child 2
|-> Child 3
Parent 1
|-> Child 0
|-> Child 1
Parent 2
|-> Child 0
|-> Child 1
|-> Child 2
|-> Child 3
|-> Child 4

I have a class for tree store like this

#include <gtkmm.h>

class TreeModel_Dnd : public Gtk::TreeStore

  //Tree model columns:
  class treeModelCol : public Gtk::TreeModel::ColumnRecord
    Gtk::TreeModelColumn<Glib::ustring> col_name;



  treeModelCol treeColumn;

  static Glib::RefPtr<TreeModel_Dnd> create();

  using onTreeviewRowDragged = sigc::signal<void>;
  onTreeviewRowDragged onTreeviewRowDragged_Fun();

  //Overridden virtual functions:
  bool row_draggable_vfunc(const Gtk::TreeModel::Path& path) const override;
  onTreeviewRowDragged onTreeviewRowDragged_Sig;


I call this in the other class

  Glib::RefPtr<TreeModel_Dnd> treeViewPointer  
  Gtk::TreeModel::Row row;

  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 0";
  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 1";
  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 2";
  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 3";
  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 4";
  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 5";
  row = *(treeViewPointer->append());
  row[treeViewPointer->treeColumn.col_name] = "Parent 6";

According to TreeView - Editable Cells

I have to create this

  Gtk::TreeView::Column treeviewColumnValidated;
  Gtk::CellRendererText cellRendererValidated;

  // Tell the view column how to render the model values:

  // Make the CellRenderer editable, and handle its editing signals:
  cellRendererValidated.property_editable() = true;



I have to append column
treeView->append_column("",treeViewPointer->treeColumn.col_name); and treeView->append_column(treeviewColumnValidated);

Which is creating two columns totally wrong.

My objective I want to be able to detect

  1. When the user starts editing the row (parent or child), which I can catch from signal_editing_started
  2. When the user completes the editing of the row, which I can catch from signal_edited

How do I create a CellRendererText to all the rows including parent & child.

Can anyone guide me?

I found this In Gtk, is it possible to have one cell renderer per treeview row?
I think this is exactly what I want but have no idea how to implement

I found this Implementing custom logic for editable cells

The way suggested there is

For instance, maybe you want to restrict the input to certain characters or ranges of values.

To achieve this, you should use the normal
Gtk::TreeView insert_column() and
append_column() methods,
then use get_column_cell_renderer()
to get the Gtk::CellRenderer used by that column.

You should then cast that Gtk::CellRenderer* to the specific CellRenderer that you expect, so you
can use specific API.

For instance,
for a CellRendererText, you would set the cell’s editable property to true, like so:
cell.property_editable() = true;

You can then connect to the appropriate “edited” signal.
For instance, connect to
Gtk::CellRendererText::signal_edited(), or
If the column contains more than one CellRenderer then you will need to use Gtk::TreeView::get_column() and
then call get_cell_renderers() on that view Column.
In your signal handler, you should examine the new value and then store it in the Model if that is
appropriate for your application.

Can anyone guide me here as to how to implement this please

Got a solution, which worked for me.

Hope it helps few others too.

I came across this Implementing custom logic for editable cells. to come up with this logic

Gtk::CellRendererText *cellT = (Gtk::CellRendererText*)(treeView->get_column_cell_renderer(0));
cellT->property_editable() = true;


I was able to get void on_my_edited(const Glib::ustring& path, const Glib::ustring& new_text)

path to know which treeview row was selected and new_text the updated new text entered by the user after he presses ENTER.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.