GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Mon Aug 29, 2016 1:53 am

All times are UTC

Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: 2 TreeView questions
PostPosted: Tue Apr 01, 2008 5:53 am 
Familiar Face

Joined: Fri Mar 07, 2008 5:35 am
Posts: 11
Location: Moscow
Hello everyone!
I have a few questions about the treeview which I was not able to find any help/documentation on.

1. I have rows that display text. If I have a VERY long string, how can I stop the column expanding to its length, but instead show those 3 neat dots on the right side of the row, which means its a long string?
2. How can I have columns alter their size by dragging the column title edge?
Thank you for your help!

 Post subject:
PostPosted: Wed Apr 02, 2008 11:22 pm 
Familiar Face

Joined: Wed Apr 02, 2008 10:53 pm
Posts: 28
Hi mr.smith

For the first question, I don't know if there is an easy way to do that,
but otherwise you could count the number of caracters of your string and alter it
with the 3 dots if it is too big:

When you create your columns, you probably do something like:

renderer = gtk_cell_renderer_text_new ();
g_object_set_data (G_OBJECT (renderer), "column", GINT_TO_POINTER (COLUMN_TEXT1));   
column = gtk_tree_view_column_new_with_attributes ("My title of column",

gtk_tree_view_column_set_cell_data_func(column, renderer, polish_column_text1_data_function_tl, NULL, NULL);
gtk_tree_view_append_column (treeview, column);

The line:

[code=]gtk_tree_view_column_set_cell_data_func(column, renderer, polish_column_text1_data_function_tl, NULL, NULL);[/code]

Allows to modify the display of the column without actually changing the content of the column.
So your full sentence will still be stored, but you will be able to modify the displayof it in your treeview.

So you have to define the polish_column_text1_data_function_tl:

static void polish_column_text1_data_function_tl (GtkTreeViewColumn *col,
                           GtkCellRenderer   *renderer,
                           GtkTreeModel      *model,
                           GtkTreeIter       *iter,
                           gpointer           user_data)
gchar * my_string;

g_object_get (renderer, "text", &my_string, NULL);
if(strlen(my_string) > 50){
my_string[46] = '.';
my_string[47] = '.';
my_string[48] = '.';
my_string[49] = '\0';
g_object_set (renderer, "text", my_string, NULL);

I tried looks like it works

For the second question, I beleive you should use
gtk_tree_view_column_set_resizable ()
documented in the GTK doc.



 Post subject:
PostPosted: Thu Apr 03, 2008 7:06 pm 
Familiar Face

Joined: Fri Mar 07, 2008 5:35 am
Posts: 11
Location: Moscow
Thanks for your reply, I will implement what you've suggested for the '3 dots'. Will I be able to do this using gtkmm, since I am not using C? As for the 1st question, I was careless and overlooked the property - in Gtk::TreeViewColumn, it is the set_resizable() function. Thanks again!

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 3 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