GTK+ Forums

Discussion forum for GTK+ and Programming. Ask questions, troubleshoot problems, view and post example code, or express your opinions.
It is currently Tue Nov 25, 2014 12:40 am

All times are UTC




Post new topic Reply to topic  [ 1 post ] 
Author Message
 Post subject: Problem with GtkEventBox and enter/leave events
PostPosted: Tue Mar 12, 2013 7:56 pm 
Offline

Joined: Tue Mar 12, 2013 12:52 pm
Posts: 1
Hello.

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:

Code:
#include <gtk/gtk.h>



GtkWidget* button1;


static
void on_enter(GtkWidget *widget,
              gpointer   data)
{
    g_print("enter\n");
    gtk_widget_set_visible(button1, TRUE);
}

static
void on_leave(GtkWidget *widget,
              gpointer   data)
{
    g_print("leave\n");
    gtk_widget_set_visible(button1, FALSE);
}

int main( int   argc,
          char *argv[] )
{
    GtkWidget *window;
    GtkWidget *button2;
    GtkWidget *box;
    GtkWidget *evt_box;

    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_widget_set_no_show_all(button1, TRUE);

    gtk_box_pack_start(GTK_BOX(box), button1, TRUE, TRUE, 0);
    gtk_box_pack_start(GTK_BOX(box), button2, TRUE, TRUE, 0);

    gtk_container_add(GTK_CONTAINER(evt_box), box);

    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);

    gtk_container_add(GTK_CONTAINER(window), evt_box);



    /* and the window */
    gtk_widget_show_all (window);
    gtk_window_resize(GTK_WINDOW(window), 400, 400);

    gtk_main ();

    return 0;
}


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.


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

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