[Gtk-sharp-list] TreeView, CellRendererSpin: Spin buttons not visible & Custom CellRenderers

TheSHEEEP thesheeep2 at web.de
Sat Mar 24 10:41:05 UTC 2012


This is also on 
http://stackoverflow.com/questions/9850979/gtk-treeview-cellrendererspin-spin-buttons-not-visible-custom-cellrenderer
Stackoverflow , and I will add the answer to both, should I receive one.

I am trying to use a spin button within my TreeView. It as added like this:

//------------------------------------------------------------------------
Gtk.TreeViewColumn adjustColumn = new Gtk.TreeViewColumn();
adjustColumn.Title = "";
Gtk.CellRendererSpin adjustCell = new Gtk.CellRendererSpin();
adjustCell.Digits = 0;
adjustCell.Adjustment = new Adjustment(0, 0, 99, 1, 99, 99);
adjustCell.Editable = true;
adjustCell.Visible = true;
adjustCell.Sensitive = true;
adjustCell.Mode = CellRendererMode.Editable;
adjustColumn.PackEnd(adjustCell, true);

adjustColumn.SetCellDataFunc(adjustCell, new
Gtk.TreeCellDataFunc(RenderAdjuster));
treeView.AppendColumn(adjustColumn);
//------------------------------------------------------------------------

And inside the rendering function the following is done:

//------------------------------------------------------------------------
(cell as Gtk.CellRendererSpin).Width = 30;
(cell as Gtk.CellRendererSpin).Height = 20;
(cell as Gtk.CellRendererSpin).Text = "" + (cell as
Gtk.CellRendererSpin).Adjustment.Value;
//------------------------------------------------------------------------

This does render the value, but the spin buttons are not visible! They only
become visible once the user clicks the value. That is absolutely
ridiculous, as there is no way the user will know that the cell is editable
other than randomly clicking in it, especially since there are other values
in the row that are not editable.

So my first question is, how can I make those spin buttons always visible?


*Could this be done with a custom CellRenderer?*

I would be thankful for an example of how to create my own, actually
working, spin button cell renderer. Unfortunately, custom cell renderers are
an undocumented mystery (as almost anything in gtk# ;) ). And all you can
find to them are examples that draw Cairo rectangles, etc. themselves. There
must be an easier way where can you simply put any widget into that
renderer, and listen to clicks, etc. and simply render the widget when the
cell is rendered.

An example for a custom CellRenderer that simply displays a button (that can
listen to clicks) would also be fine as I could at least "fake" a
SpinButton, by having three columns with a text, a "+"-Button and a
"-"-Button.


--
View this message in context: http://mono.1490590.n4.nabble.com/TreeView-CellRendererSpin-Spin-buttons-not-visible-Custom-CellRenderers-tp4501156p4501156.html
Sent from the Mono - Gtk# mailing list archive at Nabble.com.


More information about the Gtk-sharp-list mailing list