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 Apr 20, 2014 5:46 am

All times are UTC




Post new topic Reply to topic  [ 3 posts ] 
Author Message
 Post subject: Events on label widget
PostPosted: Mon Oct 29, 2012 11:43 am 
Offline
Familiar Face

Joined: Tue Oct 23, 2012 8:13 am
Posts: 5
I need to make a label widget respond to mouse clicks. But when I try to do this with g_signal_connect for "button-press-event", after setting the event mask with gtk_widget_add_events to GDK_BUTTON_PRESS_MASK my event handler is still not called. gdk_widget_set_sensitive also does not help. Is there something special about label widgets that prevents them from accepting events?

I know that it is possible to put a label inside a button, but the standard "clicked" handler for buttons does not tell me which mouse button was causing the event (which I need to know in the handler)? In addition I could not get rid of the border (GTK_RELIEF_NONE does still cause borders on my system when you operate the button, and reserves space around them to do that, both very much unwanted).

I also tried to use a button_with_label directly, manipulating the label like it was a label widget, but in this case (apart from the border problem, which is less severe in this case, as no margins are reserved between label text and border) it does not seem possible to apply the same text formatting (controlling font size and color with gtk_label_set_markup) as in true label widgets.


Top
 Profile  
 
 Post subject: Re: Events on label widget
PostPosted: Mon Oct 29, 2012 7:29 pm 
Offline
Never Seen the Sunlight

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

GtkLabel does not respond to GtkWidget::button-press-event because it doesn't have a GdkWindows associated with. If you want to catch those signals on label, you'll need to wrap it in GtkEventBox and connect to signals on this box.

Cheers,
Tadej


Top
 Profile  
 
 Post subject: Re: Events on label widget
PostPosted: Tue Oct 30, 2012 9:35 pm 
Offline
Familiar Face

Joined: Tue Oct 23, 2012 8:13 am
Posts: 5
OK, thanks. That really gave me the clue I needed to solve this. I have put the label widget inside a GtkEventBox now, and connect the signals to those. That also helped me solve another problem I was struggling with. To highlight the widget (which display clocks above a Chess board), the foreground and background colors of the text are swapped. But the text did not fill the entire area of the label widget, only the part that was written. By setting the bg color of the EventBox the same as that of the text, I can acheive perfect rectangular highlighting:

Image


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: 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:  
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group