GTK+ Forums Forum Index GTK+ Forums
Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

2 TreeView questions

 
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming
Author Message
mr.smith
Familiar Face


Joined: 07 Mar 2008
Posts: 5

PostPosted: Tue Apr 01, 2008 5:53 am    Post subject: 2 TreeView questions Reply with quote

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!
Back to top
cofcof
Familiar Face


Joined: 02 Apr 2008
Posts: 13

PostPosted: Wed Apr 02, 2008 11:22 pm    Post subject: Reply with quote

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: (C)
1
2
3
4
5
6
7
8
9
10
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: (Plaintext)
1
gtk_tree_view_column_set_cell_data_func(column, renderer, polish_column_text1_data_function_tl, NULL, NULL);


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: (C)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
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
Back to top
mr.smith
Familiar Face


Joined: 07 Mar 2008
Posts: 5

PostPosted: Thu Apr 03, 2008 7:06 pm    Post subject: Reply with quote

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!
Back to top
Display posts from previous:   
Post new topic   Reply to topic    GTK+ Forums Forum Index -> GTK+ Programming All times are GMT
Page 1 of 1

 


Powered by phpBB © 2001, 2005 phpBB Group
CodeBB 1.0 Beta 2
Protected by Anti-Spam ACP