Child GTK widget's won't hide when set in property

I have a few child widgets that I’m trying to have the visibility be toggle-able using GObject properties. Something like this would show the tray icons, and hide the launcher and user icon:

g_object_set(panel, "show-tray", TRUE, "show-launcher", FALSE, "show-user", FALSE); 

However, this apparently does not work when using a GtkBuilder file.The strangest thing that I found with this in testing is that the icons toggle just fine in the Glade UI builder application. The class is called ExpidusWidgetsPanel` and the code for it is on the ExpidusOS Shell GitHub, which I have linked, and is under src/widgets/panel.c. The widget builds partly from a Glade file, that might affect the outcome of the result but I don’t think so.

GitHub: shorturl.at/aqBC6 (Note that I had to shorten it since Discourse seems to be a bit weird with anti-spam)

Shouldn’t your g_object_set() call be null-finished? (I’m not really knowledgeable in Gtk in C.)

Also, I think GtkBuilder inits properties at the object construct stage, so you probably should use one of the G_PARAM_CONSTRUCT or G_PARAM_CONSTRUCT_ONLY flags.

No other idea.

That g_object_set is just an example of how I intended the visibility to be toggled. The widgets are meant to be shown/hidden at any time. Did you look at my code on GitHub to see what could be the issue?

What do you mean with “does not work”?

How do you set the properties in the UI file (don’t call it “Glade” file)?

How do you instantiate the object?

Do you get warnings at run time?

I just did (link) and I think you should reread my previous comment (edited) given the following answer of @ebassi, I have no other idea.

GtkBuilder constructs objects with all the properties it can; G_PARAM_CONSTRUCT and G_PARAM_CONSTRUCT_ONLY have no bearing on the properties being set: if it’s in the XML, it’ll be applied.

Additionally, template children are available as soon as gtk_widget_init_template() is called, which means by the time set_property() is called, every template child is available.

1 Like

I mean the children; tray, user, and launcher. Those widgets are still visible even though they are set as hidden here: github .com /ExpidusOS/shell/blob/master/src/greeter/greeter.glade#L30-L32

I set the visibility in code here: github .com /ExpidusOS/shell/blob/master/src/widgets/panel.c#L59-L76

No warnings at runtime, I get the object here: github .com /ExpidusOS/shell/blob/master/src/greeter/main.c#L94

Since there are no warnings, I’m assuming “gtk_widget_set_visible” is working.

Do you set the no-show-all property on those widgets? I see some calls to gtk_widget_show_all() in the code (but not sure it’s on a parent of those widgets or not).

Wild guess: Maybe it’s a problem that ExpidusWidgetsPanel is derived from GtkButton but has several other buttons as children?

The show_all call is on a GtkWindow.

I don’t think so because the other widgets are working just fine and in Glade, the UI builder program, allows me to hide and show the elements through the ExpdusWidgetsPanel properties.

So yeah, show_all changed the visibility. Thanks for pointing out that function changed ExpidusWidgetsPanel’s children.