Hi all,
I’m developing a C application based on a GtkWindow widget.
In this window I put some widgets (label and button) and based on the internal state, I show or hide some of them.
The problem is the first view: in the main() function I load a glade file, I hide some buttons then I call gtk_widget_show_all() and gtk_main() functions. At the beginning I still see the hidden buttons.
If something change (basically change the state/text or show/hide some other labels/buttons) the window is refreshed and the initial buttons finally hide.
Why this happen and how can I refresh the first view to show the correct state?
All widgets in GTK3 are hidden by default, and will be visible only if you either call show() or you set the visible property to TRUE.
Because you’re calling show_all(), you’re asking GTK to recursively show all children of a widget. You should only call show() on the widgets you want to show.
If you want to control the visibility of some child widgets, and continue calling show_all(), then you’ll have to use gtk_widget_set_no_show_all() on the widgets you don’t want show_all() to mark as visible.
Thanks.
The widgets are read from a glade file where they are set as visible.
After that, I set the visibility to FALSE, then I call the show_all().
Should they be visible? Now yes.
If your widgets are already set to visible as you’re saying, you probably should just not call show_all(), but merely show() on the main window (or nothing at all if it’s already visible). show_all() is not a must to call, it’s only a convenience to recursively show all widgets in a hierarchy (as they are hidden by default in GTK3, hence you probably having seen it in a lot of apps or examples).