Re: [gtkmm] Editable CellRendererText with custom checks



Murray Cumming <murrayc murrayc com> writes:

> On Sat, 2004-02-28 at 22:10, Roger Leigh wrote:
>> Reading from the Gtkmm tutorial (Chapter 8, editable cells), I was
>> able to create an editable column using
>> Gtk::TreeView::append_column_editable().  However, when I used plain
>> append_column() to use my own custom checking callback, like this:
>> 
>>   m_treeview->set_model(m_tree_store);
>>   int view_column = m_treeview->append_column("Title", list_columns.m_col_editable);
>>   Gtk::CellRenderer *renderer = m_treeview->get_column_cell_renderer(view_column - 1);
>>   Gtk::CellRendererText *text_renderer = dynamic_cast<Gtk::CellRendererText *>(renderer);
>>   if (text_renderer)
>>     {
>>       text_renderer->signal_edited().connect
>> 	( SigC::slot(*this, &editable_treeview::on_edited) );
>>     }
>> 
>> This doesn't do anything (the cell isn't editable) unless I add
>> 
>>       text_renderer->property_editable() = true;
>> 
>> to the "if" block.  This isn't mentioned in the tutorial, so I'm not
>> sure if it's necessary.  Am I missing something here, or is this
>> required?
>
> I don't understand. What were you trying to do? The book mentions that
> you need to use append_column_editable() to get editable columns, so
> it's natural to think that it won't be editable if you just use
> append_column().

I want an editable column, but I want to check the entered data to
validate it (to check for duplicates) prior to updating the model.

The manual says this:

,----
| Implementing custom logic for editable cells.
| [...]
| 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 cast that Gtk::CellRenderer* to the specific CellRenderer
| that you expect, and then connect to the appropriate "edited"
| signal.
`----

I've done what is said above: I've used plain append_column(), got the
CellRenderer and connected a handler to signal_edited.  However, if I
don't set the "editable" property, I can't edit.

If I use append_column_editable(), my handler appears to be ignored,
because it allows me to enter duplicates.

> Note that it takes more than property_editable()=true to make the cell
> really editable, as you can see in the implementation for
> append_column_editable() - you need to respond to an appropriate signal
> and put the new value into the model.

I've done both of these.  I was unsure as to whether setting
property_editable() was strictly necessary when validating data.  It
appears that it is, but this isn't mentioned in the manual.


Regards,
Roger

-- 
Roger Leigh

                Printing on GNU/Linux?  http://gimp-print.sourceforge.net/
                GPG Public Key: 0x25BFB848.  Please sign and encrypt your mail.



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