GtkLabel inside GtkEventBox causes gtk_label_set_text() to misbehave



I am not sure if this is a bug or not, but it is certainly unexpected.

If you put a label inside an event box, when you call
gtk_label_set_text(), the old label text is not erased before the new
label is drawn.  Labels inside buttons are redrawn correctly though.

Here is a little program to demonstrate:

- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
#include <gtk/gtk.h>

static GtkWidget* label1;
static GtkWidget* label2;
static GtkWidget* btn;

static void clicked(GtkMenuItem* menuitem, gpointer userData)
{
    static int quit;

    if (quit++) {
	gtk_main_quit();
	return;
    }
    gtk_label_set_text(GTK_LABEL(label1), "Changed");
    gtk_label_set_text(GTK_LABEL(label2), "Changed");
    gtk_label_set_text(GTK_LABEL(GTK_BIN(btn)->child), "Quit");
}

int main(int argc, char* argv[])
{
    GtkWidget* top;
    GtkWidget* vbox;
    GtkWidget* event_box;

    gtk_init(&argc, &argv);

    top = gtk_window_new(GTK_WINDOW_TOPLEVEL);
    gtk_window_set_title(GTK_WINDOW(top), "Label Funnies");

    vbox = gtk_vbox_new(FALSE, 0);
    gtk_container_add(GTK_CONTAINER(top), vbox);

    label1 = gtk_label_new("Bare label");
    gtk_box_pack_start(GTK_BOX(vbox), label1, TRUE, TRUE, 0);

    event_box = gtk_event_box_new();
    gtk_box_pack_start(GTK_BOX(vbox), event_box, TRUE, TRUE, 0);

    label2 = gtk_label_new("Label in event box");
    gtk_container_add(GTK_CONTAINER(event_box), label2);

    btn = gtk_button_new_with_label("Press Me");
    gtk_box_pack_start(GTK_BOX(vbox), btn, FALSE, TRUE, 0);
    gtk_signal_connect(GTK_OBJECT(btn), "clicked",
		       GTK_SIGNAL_FUNC(clicked), NULL);

    gtk_widget_show_all(top);

    gtk_main();
    return 0;
}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]