I have a Custom Widget created based on a template.
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="MyWidget" parent="GtkWidget">
<object class="GtkBox" id="box">
...
</object>
</template>
</interface>
[GtkTemplate (ui = "..mywidget.ui")]
public class MyWidget : Gtk.Widget {
[GtkChild]
private unowned Gtk.Box box;
private Gtk.Widget child;
public MyWidget () {
box.set_parent(this);
child = box;
}
public override void size_allocate (int width, int height, int baseline)
{
...
}
protected override void dispose () {
...
}
}
If I create a Widget object and add it as a child of another, it works and displays correctly
child = new MyWidget ();
....
But if I place that widget as a child of another in a template, it is not displayed.
<?xml version="1.0" encoding="UTF-8"?>
<interface>
<requires lib="gtk" version="4.0"/>
<template class="MyPopover" parent="GtkPopover">
<child>
<object class="MyWidget" id="myWidget">
</object>
</child>
</template>
</interface>
[GtkTemplate (ui = "...popover.ui")]
public class MyPopover : Gtk.Popover {
/* It is not displayed if it is as a child in a template */
[GtkChild]
private unowned MyWidget myWidget;
public Popover () {
/* It is only displayed if I manually add it as a child */
// child = new MyWidget();
}
}
Somebody could help me?