GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Wed Aug 31, 2016 4:21 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: GTK TreeView with Doubles Shown in Exponential Notation
PostPosted: Thu May 23, 2013 7:19 pm 
Familiar Face

Joined: Tue Oct 30, 2012 2:25 am
Posts: 6
I am writing a data fitting application, and I compare many different fits to the data in a List Store. I display many doubles in the List Store, but the numbers are shown in standard format even if it doesn't make sense. For instance the number 0.00000001 is listed as 0.000000 instead of 1.000e-8 which uses the same number of characters. So the numbers are converted into strings by the %f format instead of %e or %g. This is quite frustrating because different data is easier or harder to fit, so I have numbers that go across many magnitudes.

I could format the strings myself, but that would take a lot of extra code, and I would like to know if there is a way to get the ListStore to display in exponential format preferably using the %g way. I tried looking through the properties for TreeView, TreeModel, and Liststore, but do not see anything.

 Post subject: Re: GTK TreeView with Doubles Shown in Exponential Notation
PostPosted: Tue May 28, 2013 6:54 am 
Never Seen the Sunlight

Joined: Mon Apr 28, 2008 5:52 am
Posts: 1048
Location: UK

GTK+ has only one default conversion for floating point numbers for Tree Views. It does this by using the %f format and using the string displays it using the GtkCellRendererText object. You can change this behaviour by changing the default Tree View mapping function by using the function gtk_tree_view_column_set_cell_data_func (). This sets a function to be called whenever data needs to be displayed.

Within the call-back function do the required conversion and then set the GtkCellRendererText property "text" to the resulting string.

This should not be very much code and you can select different output formats just by changing the call-back function you set with gtk_tree_view_column_set_cell_data_func ().


Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: Yahoo [Bot] and 2 guests

You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group