GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Thu Oct 23, 2014 4:31 pm

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 
Offline
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!


Top
 Profile  
 
 Post subject:
PostPosted: Wed Apr 02, 2008 11:22 pm 
Offline
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:

Code:
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",
                       renderer,
                       "text",
                       COLUMN_TEXT1);
                       NULL);

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:


Code:
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);
}
g_free(my_string);
}


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.

Cheers

CofCof


Top
 Profile  
 
 Post subject:
PostPosted: Thu Apr 03, 2008 7:06 pm 
Offline
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!


Top
 Profile  
 
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: Google [Bot] and 3 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