I am writing a custom widget which will be displayed within an AppWindow (AdwApplicationWindow) using AdwOverlaySplitView for the utility pane.
However, when I placed my custom widget which contains a GtkLabel itself under the 'content' property of AdwOverlaySplitView, it did not appear. But, when I used a GtkLabel instead, it was displayed correctly.
Here are my .ui and .c files
app-window.ui
?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="AppWindow" parent="AdwApplicationWindow">
<property name="content">
<object class="AdwToolbarView">
<child type="top">
<object class="AdwHeaderBar" id="header_bar">
<child type="start">
<object class="GtkToggleButton" id="show_sidebar_button">
<property name="icon-name">panel-left-symbolic</property>
<property name="tooltip-text" translatable="yes">Toggle Sidebar</property>
<property name="active">True</property>
</object>
</child>
<child type="end">
<object class="GtkMenuButton">
<property name="primary">True</property>
<property name="icon-name">open-menu-symbolic</property>
<property name="tooltip-text" translatable="yes">Menu</property>
<property name="menu-model">primary_menu</property>
</object>
</child>
</object>
</child>
<property name="content">
<object class="AdwOverlaySplitView" id="split_view">
<property name="show-sidebar" bind-source="show_sidebar_button" bind-property="active" bind-flags="sync-create|bidirectional"/>
<property name="sidebar">
<!-- Sidebar content-->
</property>
<property name="content">
<!-- Main Page content -->
<object class="MyWidget"> <!-- This is not getting displayed -->
</object>
<object class="GtkLabel">
<property name="label">Label</property> <!-- This is getting displayed -->
</object>
</property>
</object>
</property>
</object>
</property>
</template>
</interface>
my-widget.ui
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<requires lib="Adw" version="1.0"/>
<template class="MyWidget" parent="GtkWidget">
<object class="GtkLabel">
<property name="label">Label</property>
</object>
</template>
</interface>
my-widget.c
struct MyWidget
{
GtkWidget parent_instance;
};
G_DEFINE_TYPE (MyWidget, my_widget, GTK_TYPE_WIDGET)
static void
my_widget_init (MyWidget *self)
{
gtk_widget_init_template (GTK_WIDGET (self));
}
static void
my_widget_class_init (MyWidgetClass *klass)
{
GtkWidgetClass *widget_class = GTK_WIDGET_CLASS (klass);
gtk_widget_class_set_template_from_resource (widget_class, "<resource_path>");
}
I used the GTK Inspector, and it was able to idenity the widget. However, visually, there is no output.
Even though I've worked with .ui files before, they still confuse me. What am I doing wrong here?