# CellRendererSpin - how to use?

**URL:** <https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864>\
**Category:** Ruby-Gnome 2\
**Created:** [January 4, 2009, 1:44pm UTC](https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864 "2009-01-04T13:44:57Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [January 4, 2009, 1:44pm UTC](https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864/1 "2009-01-04T13:44:57Z")

</div>

Hello

I tried writing a small Hello World style application with ruby-gtk2.

After I was told that ‘list’ and ‘table’ are both spelled ‘treeview’  
in GTK I was able to put together a small demo that actually allows  
editing a list of text strings.

Howeveer, I cannot make the SpinButton cell renderer to display, and  
there is no GTK warning or anything that would indicate there is  
something wrong.

Is there some demo showing the less common cell renderers? I was  
looking at the gtk-demo but it uses CellRendererText for numbers.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [January 23, 2009, 8:28am UTC](https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864/2 "2009-01-23T08:28:19Z")

</div>

Michal S. wrote:

> Hello
> 
> I tried writing a small Hello World style application with ruby-gtk2.
> 
> After I was told that ‘list’ and ‘table’ are both spelled ‘treeview’  
> in GTK I was able to put together a small demo that actually allows  
> editing a list of text strings.
> 
> Howeveer, I cannot make the SpinButton cell renderer to display, and  
> there is no GTK warning or anything that would indicate there is  
> something wrong.
> 
> Is there some demo showing the less common cell renderers? I was  
> looking at the gtk-demo but it uses CellRendererText for numbers.
> 
> Thanks
> 
> Michal

Take a look at:

[http://www.kksou.com/php-gtk2/articles/input-or-edit-numbers-in-GtkTreeView-with-GtkCellRendererSpin.php](http://www.kksou.com/php-gtk2/articles/input-or-edit-numbers-in-GtkTreeView-with-GtkCellRendererSpin.php)

HTH,  
Roy

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [January 30, 2009, 3:00pm UTC](https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864/3 "2009-01-30T15:00:43Z")

</div>

On 23/01/2009, Roy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > there is no GTK warning or anything that would indicate there is  
> > Take a look at:
> 
> [http://www.kksou.com/php-gtk2/articles/input-or-edit-numbers-in-GtkTreeView-with-GtkCellRendererSpin.php](http://www.kksou.com/php-gtk2/articles/input-or-edit-numbers-in-GtkTreeView-with-GtkCellRendererSpin.php)

Thanks for the sample. It seems they set the value property from the  
model rather than the adjustment property. Although the docs seem to  
indicate that either should be possible maybe it is not.

I will try a few modifications of my hello world and see how it goes.

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [February 26, 2009, 12:28am UTC](https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864/4 "2009-02-26T00:28:48Z")

</div>

On 26/02/2009, Michal S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> > 
> 
> somewhere, and I am not aware of ever doing that.
> 
> In fact I can type an exact value and my handler sets it into the  
> model (I wish there was a default handler doing just that) but  
> whenever the value is loaded into the spinbutton it is rounded.

It’s because the renderer displays the value differently when inactive  
and while editing. It can be seen by uncommenting the part with  
set\_digits()

The value is a plain label normally with many decimal places but the  
spinbutton only has as many decimal digits as set with the digits  
property thus the value is rounded when loaded into the spinbutton.

The odd things that happen here are two:

- the renderer sets digits on the spinbutton but does not heed the  
property for the label
- the spinbutton rounds the value when set but allows entering exact  
value manually

Thanks

Michal

---

<div class="post-metadata">

**Author:** ![Michal\_S](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/779978/32.png) [@Michal\_S](https://www.ruby-forum.com/u/Michal_S)\
**Post date:** [February 26, 2009, 12:21am UTC](https://www.ruby-forum.com/t/cellrendererspin-how-to-use/156864/5 "2009-02-26T00:21:44Z")

</div>

Hello

On 23/01/2009, Roy W. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid) wrote:

> Take a look at:
> 
> [http://www.kksou.com/php-gtk2/articles/input-or-edit-numbers-in-GtkTreeView-with-GtkCellRendererSpin.php](http://www.kksou.com/php-gtk2/articles/input-or-edit-numbers-in-GtkTreeView-with-GtkCellRendererSpin.php)

Thanks for this sample.

It shows clearly that the cell renderers have an undocumented property  
text which also gets propagated as the value of the  
GtkCellRendererSpin adjustment.

However, there is a bug somewhere that prevents me from incrementing  
the spinbutton value in non-integer steps. The value gets rounded  
somewhere, and I am not aware of ever doing that.

In fact I can type an exact value and my handler sets it into the  
model (I wish there was a default handler doing just that) but  
whenever the value is loaded into the spinbutton it is rounded.

Attaching the test program, hopefully file this time.

Thanks

Michal
