GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Sun Aug 28, 2016 8:38 am

All times are UTC

Post new topic Reply to topic  [ 2 posts ] 
Author Message
 Post subject: Buttons stealing signals :(
PostPosted: Sat Jun 07, 2008 9:48 pm 
GTK+ Geek

Joined: Wed May 28, 2008 5:49 pm
Posts: 66
I've got a gtktoolbar inside a gtkhandlebox, and the toolbar seems to be stealing my 'button-release-event' from my handlebox - ie, when I click a button on a part of a handlebox that the toolbar doesn't cover, it works, but when I click on the part that the toolbar does cover, it doesn't.

Any idea on how to make my handlebox take precedence over the buttons, or make the buttons to pass on the signals?

 Post subject:
PostPosted: Mon Jun 09, 2008 7:06 pm 
Never Seen the Sunlight

Joined: Wed Sep 21, 2005 12:07 am
Posts: 563
Location: Portland, OR USA
This was also posted on Ubuntu Forums:

Okay, I did a little test and although not "easy", it works.

A GtkToolButton is derived from GtkToolItem which is derived from GtkContainer. Peaking at the source for GtkToolButton, I see that it simply packs a GtkButton into itself. So, if we can get that GtkButton then we could connect to that button's "button-press-event". A GtkToolButton does not give you direct access to it's child GtkButton, however, we can use GtkContainer's functions to do so.

You can:

1. Get each GtkToolButton using gtk_builder_get_object()
2. Get a GList containing the children using gtk_container_get_children()
3. Get the first child using g_list_first() (this will be a GtkButton)
4. Connect to the button-press-event of that GtkButton.
5. In your handler, if it's a right click do what you gotta do and return TRUE. Otherwise return FALSE to let the normal handlers run.

This is a bit tedious, however, you can use the same function to handle the "button-press-event" for every button and you could write a loop using gtk_toolbar_get_n_items() and gtk_toolbar_get_nth_item() rather than calling gtk_builder_get_object() on every GtkToolButton.

You may want to run this idea through the gtk-app-devel mailing list to get some feedback from those guys' as I've never had to do this. I would also put some checks to make sure that the child widget you get using gtk_container_get_child is in fact a GtkButton (GTK_IS_BUTTON()).

Micah Carrick - Forum Administrator

Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 2 posts ] 

All times are UTC

Who is online

Users browsing this forum: No registered users and 1 guest

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