GTK+ Forums

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

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Selecting single cell rather than a whole row in treeview?
PostPosted: Sat Jan 24, 2009 2:05 pm 
Offline
Familiar Face

Joined: Thu Jan 22, 2009 2:15 pm
Posts: 15
Is there an easy way to do this? I think the standard selection mode is limited to visibly selecting the whole row. Is there a simple way to only show one cell selected even if the whole row is considered selected?

I have simple rows containing only 1 column with 2 cells packed. First cell is a pixbuf type and the second a text type. When I click on it to select the row, I only want the text to show as selected.


Top
 Profile  
 
 Post subject:
PostPosted: Sun Jan 25, 2009 2:28 am 
Offline
Familiar Face

Joined: Sun Nov 23, 2008 8:14 pm
Posts: 41
The ONLY way to do that is with Cell Data functions.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 8:01 am 
Offline
GTK+ Geek

Joined: Sun Dec 07, 2008 4:46 pm
Posts: 56
Do you mean a GtkTreeSelectionFunc or a cell renderer data func, and how is it done exactly?


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 10:39 am 
Offline
Never Seen the Sunlight

Joined: Wed Jul 23, 2008 10:31 am
Posts: 2406
Location: Slovenia
Hello.

If I were to do it, this would be the way:
1. Set GtkTreeView's selection mode to GTK_SELECTION_NONE.
2. Add additional column of GDK_TYPE_COLOR to treeview's model.
3. Connect my handler to treeview's "button-press-signal".
4. From handler obtain iter to the clicked line.
5. Set the GDK_TYPE_COLOR column to widget->style->bg[GTK_STATE_SELECTED]

I don't have time to write sample code, but if there will be interest in it, I'll do it on Wednesday.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 3:45 pm 
Offline
GTK+ Geek

Joined: Sun Dec 07, 2008 4:46 pm
Posts: 56
Yes tadeboro I am interested. I will have a go at producing the code based on your overview. I want to be able to choose and edit individual cells from a row of 16 columns, only highlighting the individual cell. In fact I would like to be able to set the cursor on individual characters in a cell containing just 2 digits representing a hexadecimal number, and be able to edit either character individually by moving the cursor with the keyboard.

I am describing a hexadecimal editor, and to be honest, I'm not sure if a treeview is the best way to implement this.

I am attempting to do this with limited knowledge of Gtk, gleaned from the internet. I have now ordered a book to assist. Thanks for your help.


Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 10:09 pm 
Offline
GTK+ Geek

Joined: Sun Dec 07, 2008 4:46 pm
Posts: 56
Here is my solution, pieced together from looking at the API and using trial and error.

It works fine. Sets the cursor focus on the cell to be edited. However, when I click below the cell area where there is no data I get a Gtk CRITICAL **:gtk_tree_view_set_cursor_on_cell: assertion path != NULL failed.......

Code:
GtkTreeSelection *selection;

selection = gtk_tree_view_get_selection(GTK_TREE_VIEW(editor->editor_treeview));
gtk_tree_selection_set_mode(selection, GTK_SELECTION_NONE);

//Initialisation code to attach the handler
gtk_signal_connect(GTK_OBJECT(editor->editor_treeview),"button_press_event",
               (GtkSignalFunc)on_editor_treeview_button_press_event,NULL);
   
gtk_widget_set_events(editor->editor_treeview, GDK_BUTTON_PRESS_MASK);

//Set for all those columns that can be edited and need the focus
g_object_set(renderer,"editable", TRUE,"editable-set", TRUE,NULL);



//The button press handler
void
on_editor_treeview_button_press_event(GtkWidget *treeview, GdkEventButton *event)
{
   GtkTreePath *apath;
   GtkTreeViewColumn *acolumn;
   
   gint x;
   gint y;
   
   apath = gtk_tree_path_new();
   acolumn = gtk_tree_view_column_new();
   
   
   gint *cell_x = NULL;
   gint *cell_y = NULL;
   
   x = event->x;
   y = event->y;;
   
   gtk_tree_view_get_path_at_pos(GTK_TREE_VIEW(treeview),
                          x,
                          y,
                          &apath,
                          &acolumn,
                          cell_x,
                          cell_y);
   
   gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview),apath,acolumn,TRUE);
   
   return;
   
   
}


Last edited by dell_boy on Tue Jan 27, 2009 7:42 am, edited 1 time in total.

Top
 Profile  
 
 Post subject:
PostPosted: Mon Jan 26, 2009 10:28 pm 
Offline
GTK+ Geek

Joined: Sun Dec 07, 2008 4:46 pm
Posts: 56
I stopped the error message by changing the last line to:

Code:
if(apath)
        {
         gtk_tree_view_set_cursor(GTK_TREE_VIEW(treeview),apath,acolumn,TRUE);
}



Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 7 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users 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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group