[no subject]



namespace Gtk
{
  namespace TreeViewColumn_CellRendererGeneration
  {
    template<>
    CellRenderer* generate_cell_renderer<numeric>(bool editable)
    {
      CellRendererNumeric* pCellRenderer = new CellRendererNumeric();
      pCellRenderer->property_editable() = editable;
      return pCellRenderer;
    }
  }
}

Is adding support for my own types into your namespace OK?


>> I've written a custom class, numeric, which does fast fixed-point
>> arithmetic.  I'd like to display this directly in a Gtk::TreeView.
>> After adding it to the TreeModel, and then adding the column to the
>> view, no problems occur, but when I try to set the data, I get errors:
>> 
>> (test:24166): GLib-GObject-WARNING **: unable to set property
>> `text' of type `gchararray' from value of type `glibmm__CustomBoxed_N4EPIC7numericE'
>
> I guess you are using the TreeViewColumn::append_column() convenience
> method, which tries to do something appropriate for you. But GTK+
> doesn't know how to convert your custom type to a string (it uses a text
> CellRenderer by default). I suggest that you try doing it the long way:
> http://www.gtkmm.org/gtkmm2/docs/tutorial/html/ch08s02.html#id2494811
>
> I doubt that any of the existing CellRendererText properties will be
> appropriate though, as you've found, so you probably do need to either
> derive a custom CellRenderer, or use the cell_data_func() callback.

I don't want to use cell_data_func, because it's too much work (the
same code repeated tens of times in several treeviews).  A custom
cellrenderer is what I'd like, since I only need to do it once.

If I create a custom cell renderer, from the docs you mentioned I need
something like this:

Gtk::CellRendererNumeric* pRenderer = Gtk::manage( new Gtk::CellRendererNumeric() );
int cols_count = m_TreeView.append_column("Number", *pRenderer);
Gtk::TreeViewColumn* pColumn = m_TreeView.get_column(cols_count-1);
if(pColumn)
{
  pColumn->add_attribute(pRenderer->property_numeric(), m_columns.number);
}

And it's even easier if I use the code above.

My question here: I need a property_numeric() property, so I can set
the number being rendered.  If I derive from CellRendererText, I can
then set property_text() as a side effect.  However, I assume that due
to being a wrapper, I need to actually set a property ("numeric") in
the underlying GObject, with g_object_install_property(), and wrap
that with a PropertyProxy.  Since I have a C++ type (numeric), I'm not
sure how to do that (GValue?), since I need to somehow create a
GParamSpec to install as a property (I didn't see this wrapped).

Is this correct?  Or is there an easier way?


Thanks,
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]