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 Nov 24, 2014 5:52 pm

All times are UTC




Post new topic Reply to topic  [ 7 posts ] 
Author Message
 Post subject: Subclass GtkTreeView
PostPosted: Mon Dec 10, 2007 11:00 pm 
Offline
Familiar Face

Joined: Mon Dec 10, 2007 10:57 pm
Posts: 9
Hello,

am an experienced c++ programmer and used to work with Qt before - but now i have to develop some things with Gtk and therefore kindly ask for help.
I have to subclass GtkTreeView so that each selected row (single selection mode) gets a different font than the unselected items (at least a different font size).

Is this possible? Can someone please point me to the right direction where and how to start?

Thx for any help,

Roland


Top
 Profile  
 
 Post subject:
PostPosted: Mon Dec 10, 2007 11:16 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You could connect a callback to the "cursor-changed" signal of the GtkTreeView and change the "font" property of the GtkCellRendererText on the selected item.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 9:23 am 
Offline
Familiar Face

Joined: Mon Dec 10, 2007 10:57 pm
Posts: 9
hmm, thanks

got that far - but how to get the active/selected item

in my callback font_change i got

GtkTreeSelection *s = gtk_tree_view_get_selection(treeview);

But how to get the selected item now? Or the appropriate CelRenderer?

Thx,

roland


Top
 Profile  
 
 Post subject:
PostPosted: Tue Dec 11, 2007 5:11 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
I know I've done this in the past, I just couldn't remember how... until now.

Instead of using the "text" attribute when creating the column, use the "markup" attribute. Then in the callback function, you can use gtk_tree_store_set() with Pango markup.

So, from the selection you use gtk_tree_selection_get_selected() to get the selected iter, and then gtk_tree_store_get() to get the current value, and gtk_tree_store_set() to change it, adding markup to it.

See
http://library.gnome.org/devel/pango/unstable/PangoMarkupFormat.html for a list of markup tags.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 11:14 pm 
Offline
Familiar Face

Joined: Mon Dec 10, 2007 10:57 pm
Posts: 9
Thx,

works now.
But i have to unset the previous selected item. So i did in my selection_changed_cb:

if (lastSelectedIter != NULL)
{
gtk_list_store_set(GTK_LIST_STORE(data), lastSelectedIter, PRODUCT, unselectedString, -1);
}
if (gtk_tree_selection_get_selected(selection, &model, &iter))
{
lastSelectedIter = &iter;
....

Which gives me a warning for an invalid iter; but then how to retrieve/store the old selection.

Thx,

Roland


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 26, 2007 11:36 pm 
Offline
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
You may want to hold on the the path rather than the iter. Perhaps store the last selected path in a static variable within that callback. Iters become invalid quickly where as paths will be the same until you add or remove data.

_________________
Micah Carrick - Forum Administrator
http://www.micahcarrick.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 27, 2007 6:36 pm 
Offline
Familiar Face

Joined: Mon Dec 10, 2007 10:57 pm
Posts: 9
Storing the path solved it.

Thx.


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: Exabot [Bot], Yahoo [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:  
cron
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group