Having trouble with templates for composite widgets

Hello all, thank you for this nice library.

I’m writing a gtk4 image viewer and I’d like to use a template for a custom sub-widget (the custom widget is a display control bar with a menu and a few sliders).

The thing builds OK, but the first time it hits the main loop I see:

(vipsdisp:295869): Gtk-WARNING **: 10:51:51.888: Trying to snapshot GtkActionBar 0x55a38d7e0dd0 without a current allocation

The actionbar is the first child of my custom widget. The UI file is:

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <template class="Conversionview" parent="GtkWidget">
    <child>
      <object class="GtkActionBar" id="action_bar">
        <property name="revealed">false</property>
        <child type="start">
          <object class="GtkButton">
            <property name="label">Replace</property>
            <property name="action-name">win.replace</property>
          </object>
        </child>
      </object>
    </child>
  </template>
</interface>

I’m calling gtk_widget_init_template() in my _init() but I guess that’s not enough in this case to link the actionbar into the scene graph correctly (is that right?). Do I need to do anything else?

I’ve searched the gtk4 examples and there doesn’t seem to be one that makes a composite widget with a UI file. Is this supported? I’ve tried with gtk 4.3.2 and with gtk master.

My code is here fwiw:

Your ConversionView does not allocate a size to its GtkActionBar child widget. I.e., you need to implement size_allocate() or use an appropriate LayoutManager.

Yes, adding:

        gtk_widget_class_set_layout_manager_type( widget_class, GTK_TYPE_BIN_LAYOUT );

fixed it. Thank you @baedert !

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.