Re: Error showing widgets from a thread



Hello,

On Tue, Jul 11, 2006 at 11:49:53AM +0200, Frank Loemker wrote:
> But a simplified test case without the thread (see
> below) shows the same behavior. It first creates the first part of the
> interface (window > notebook -> scrolled window with viewport -> vbox ->
> first button) and shows it with "gtk_widget_show_all (window)". After that
> a second button is created, added to the vbox, and shown with
> "gtk_widget_show_all()".
> 
> Only if the second notebook page is active during creation of the second
> button the button is shown correctly. Otherwise the button is only shown
> if I press the first button as shown in the image at
> 
>     http://www.techfak.uni-bielefeld.de/~floemker/gtk_show.png

Seems a possible work around is to change the resize mode of the viewport
from GTK_RESIZE_QUEUE to GTK_RESIZE_PARENT. But this has of course the
disadvantage that the size calculations are slowed down. So it is probably
just a bad work around for the real problem.

> ----------------------------------------------------------------------
> #include <stdio.h>
> #include <gtk/gtk.h>
> 
> int main (int argc, char **argv)
> {
>     GtkWidget *window, *vbox, *widget, *notebook;
> 
>     gtk_init (&argc, &argv);
> 
>     window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
>     gtk_window_set_default_size (GTK_WINDOW (window), 200, 130);
> 
>     notebook = gtk_notebook_new ();
>     gtk_container_add (GTK_CONTAINER(window), notebook);
> 
>     vbox = gtk_vbox_new (FALSE, 0);
>     gtk_notebook_append_page (GTK_NOTEBOOK(notebook), vbox, NULL);
> 
>     vbox = gtk_vbox_new (FALSE, 0);
>     widget = gtk_scrolled_window_new (NULL, NULL);
>     gtk_scrolled_window_add_with_viewport (GTK_SCROLLED_WINDOW(widget), vbox);

Here adding
      gtk_container_set_resize_mode (GTK_CONTAINER(GTK_BIN(widget)->child),
                                     GTK_RESIZE_PARENT);
works around the problem.

>     gtk_notebook_append_page (GTK_NOTEBOOK(notebook), widget, NULL);
> 
>     widget = gtk_button_new_with_label ("Test1");
>     gtk_box_pack_start(GTK_BOX(vbox), widget, FALSE, FALSE, 5);
> 
>     gtk_widget_show_all (window);
> 
>     /* Works correctly if this is done:
>        gtk_notebook_set_page (GTK_NOTEBOOK(notebook), 1); */
> 
>     widget = gtk_button_new_with_label ("Test");
>     gtk_box_pack_start (GTK_BOX(vbox), widget, FALSE, FALSE, 5);
>     gtk_widget_show_all (widget);
> 
>     printf ("VISIBLE(button) %d\n", GTK_WIDGET_VISIBLE(widget));
> 
>     gtk_main();
>     return 0;
> }

Regards,

-- 
Frank Loemker



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