Re: Treeview with editable checkboxes besides items?



That's not really how this works. Instead:

- You associate the renderer with an e.g. boolean column: column->add_property (*cell, "active", your_column_record_instance.bool_col);
- You connect to the toggled() signal: cell->signal_toggled().connect  (sigc::mem_fun (*this, &YourClass::callback_toggled))
- In the handler you do something like:

void
callback_toggled (Glib::ustring const& string_path)
{
  TreeIter iter = your_model->get_iter (string_path);
  (*iter)[your_column_instance.bool_col] = !bool ((*iter)[your_column_instance.bool_col]));
}

Because, really, a cell renderer is in the first place only there to represent data.

Having a "togglebutton cellrenderer" might be confusing at first because it seems to imply that now the view can handle model data by itself, but in fact for TreeView the model is read only.

Even in an "editing-done" callback for a CellRendererText, you are only being supplied with the new text, and are still responsible for effectively updating the model yourself (in the most simple case, analogous to the above code, set the new text into the model column the relevant cell is displaying).

-- Milosz

On 6/19/07, Jef Driesen <jefdriesen hotmail com> wrote:
smso graduate hku hk wrote:
> The signature of the function  "add_attribute()" in:
>
> pColumn->add_attribute(pActive->property_active (), m_columns.active);
>
> does not match with those in the api.
> API Reference:
> http://www.gtkmm.org/docs/gtkmm-2.4/docs/reference/html/classGtk_1_1TreeViewColumn.html
>
> "pActive->property_active ()" should return either "true" or "false"

I think you are wrong here. It does match with the signature of the
second add_attribute variant:

void Gtk::TreeViewColumn::add_attribute (
    const Glib::PropertyProxy_Base& property,
    const TreeModelColumnBase& column)

> I have placed Gtk::CellRendererToggle and Gtk::CellRendererText in the same
> Gtk::TreeViewColumn
> The toggle renderer can be checked or unchecked.
> Here are some codes that I used:
>
>       renderer_toggle.property_activatable() = true;
>       treeview_col.set_title("Selected");
>       treeview_col.pack_start(renderer_toggle, true);
>       treeview_col.add_attribute(renderer_toggle, "active", 0);

You pack only one cellrenderer in the column and use one of the other
"add_attribute" functions, but for the rest the code is the same as mine
(I checked and your variant has the same problem, even with only one
cellrenderer). You are right when you say the toggle renderer can be
checked or unchecked (by changing the boolean value in the underlying
model through code). But I can't modify that value through the user
interface!

If I simply do:

m_treeview->append_column_editable ("Active", m_columns.active);
m_treeview->append_column ("Name", m_columns.name);

the values can be changed through the user interface as expected. But
this creates two separate columns (see screenshot [1]), but I only want
one (see screenshot [2]).

[1] http://users.telenet.be/sacn/tmp/treeview_2.png
[2] http://users.telenet.be/sacn/tmp/treeview_3.png

> By the way,
> I try to use `property_editable' but the compiler complains with:
> `class Gtk::CellRendererToggle' has no member named `property_editable'

CellRendererToggle does not have a 'property_editable'. That property is
for use with CellRendererText.

> Please make sure you are using the most recent version of Gtkmm.

I'm using packages from Ubuntu Feisty:

$pkg-config --modversion gtkmm-2.4 gtk+-2.0
2.10.8
2.10.11

_______________________________________________
gtkmm-list mailing list
gtkmm-list gnome org
http://mail.gnome.org/mailman/listinfo/gtkmm-list



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]