I'd like to have a GtkContainer and when the mouse cursor is over the container, I want to show certain child widgets of it and hide them when the mouse cursor is not over the container. To accomplish that, I'm using a GtkEventBox and just adding a GtkBox to it.
My code currently looks like that:
void on_enter(GtkWidget *widget,
void on_leave(GtkWidget *widget,
int main( int argc,
char *argv )
gtk_init (&argc, &argv);
window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
gtk_container_set_border_width (GTK_CONTAINER (window), 10);
button1 = gtk_button_new_with_label ("FOO");
button2 = gtk_button_new_with_label ("BAR");
box = gtk_box_new (GTK_ORIENTATION_HORIZONTAL, 10);
evt_box = gtk_event_box_new();
gtk_box_pack_start(GTK_BOX(box), button1, TRUE, TRUE, 0);
gtk_box_pack_start(GTK_BOX(box), button2, TRUE, TRUE, 0);
g_signal_connect(evt_box, "enter-notify-event", G_CALLBACK(on_enter), NULL);
g_signal_connect(evt_box, "leave-notify-event", G_CALLBACK(on_leave), NULL);
/* and the window */
gtk_window_resize(GTK_WINDOW(window), 400, 400);
If you compile and run this example, you will notice the following behavior:
- If you move your cursor first in the left side of the big BAR button, you are now over the FOO button and can click it like normal. If you now move your cursor on the BAR button again(which is now smaller and on the right), the FOO button will disappear again(which shouldn't happen).
- Now the interesting part: If you move your cursor over the right half of the BAR button first, the FOO button will now appear and you can click the BAR button like normal. Howerver, once you move your cursor over the FOO button, the program is stuck in an infinite loop of enter/leave events.
Can someone explain to me why this happens and how I can still implement it the way I want?
Thanks in advance.