What's the best way to display fractions in a TreeView

View: New views
3 Messages — Rating Filter:   Alert me  

What's the best way to display fractions in a TreeView

by Slug :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

I'm really having a lot of trouble figuring out how I should go about displaying a bunch of numeric values as fractions in a TreeView.  If I convert them to strings and load them into the model, then the sorting is all out of order when I click on the column header.  It looks like this (which is wrong):
     1    1/4
     11  1/2
     2    3/4

Is there a delegate I can invoke in the TreeStore or on CellRendererText where I can stick the code that converts the raw numeric values in the model to the formatted strings that get displayed in the end?   Or, do I have to create a subclass
( e.g. CellRendererFractionText : CellRendererText )  and then override the Render method.  This seems like a huge hassle for something so common - especially because there are no simple examples on how to do this for just a simple little bit of read only text.  

I must be totally missing something big and obvious  - what is it ?

thx - Slugs

Re: What's the best way to display fractions in a TreeView

by Matjaž Mihelič :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, 2009-07-24 at 15:19 -0700, Slug wrote:
> I'm really having a lot of trouble figuring out how I should go about
> displaying a bunch of numeric values as fractions in a TreeView.  If I
> convert them to strings and load them into the model, then the sorting is
> all out of order when I click on the column header.  It looks like this
> (which is wrong):
>      1    1/4
>      11  1/2
>      2    3/4
>

use double or decimal as store value, use CellRendererText and then use
cell function
  TreeViewColumn.SetCellDataFunc(CellRenderer,TreeCellDataFunc)
to calculate Text value;)

> Is there a delegate I can invoke in the TreeStore or on CellRendererText
> where I can stick the code that converts the raw numeric values in the model
> to the formatted strings that get displayed in the end?   Or, do I have to
> create a subclass
> ( e.g. CellRendererFractionText : CellRendererText )  and then override the
> Render method.  This seems like a huge hassle for something so common -
> especially because there are no simple examples on how to do this for just a
> simple little bit of read only text.  
>
> I must be totally missing something big and obvious  - what is it ?
>
> thx - Slugs
>

_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list

Re: What's the best way to display fractions in a TreeView

by Chris Howie :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

On Fri, Jul 24, 2009 at 6:19 PM, Slug<toddglodek@...> wrote:
> I'm really having a lot of trouble figuring out how I should go about
> displaying a bunch of numeric values as fractions in a TreeView.  If I
> convert them to strings and load them into the model, then the sorting is
> all out of order when I click on the column header.  It looks like this
> (which is wrong):
>     1    1/4
>     11  1/2
>     2    3/4

You might look at Gtk.TreeSortable.SetDefaultSortFunc.  Most models
implement the TreeSortable interface.

--
Chris Howie
http://www.chrishowie.com
http://en.wikipedia.org/wiki/User:Crazycomputers
_______________________________________________
Gtk-sharp-list maillist  -  Gtk-sharp-list@...
http://lists.ximian.com/mailman/listinfo/gtk-sharp-list