Handy error: 'titlebar' is not a valid child type of 'HdyApplicationWindow'

Hello! I am converting a small app to libhandy. However, I encountered a small error when switcing my .ui over. The error is the title of this topic. My code (or at least a snippet) looks like this:

<interface>
  <requires lib="gtk+" version="3.24"/>
  <requires lib="libhandy" version="1.0"/>
  <template class="RandomWindow" parent="HdyApplicationWindow">
    <property name="can-focus">False</property>
    <property name="default-width">400</property>
    <property name="default-height">200</property>
    <child type="titlebar">
     <!-- error above -->
      <object class="HdyHeaderBar">
        <property name="visible">True</property>
        <property name="can-focus">False</property>
        <property name="show-close-button">True</property>
        <child type="title">
          <object class="GtkStackSwitcher">
            <property name="visible">True</property>
            <property name="can-focus">False</property>
            <property name="icon-size">2</property>
            <property name="stack">stack1</property>
          </object>
        </child>
        <child>
          <object class="GtkButton">
            <property name="visible">True</property>
            <property name="can-focus">True</property>
            <property name="receives-default">True</property>
            <property name="action-name">app.about</property>
            <child>
              <object class="GtkImage">
                <property name="visible">True</property>
                <property name="can-focus">False</property>
                <property name="icon-name">help-about-symbolic</property>
              </object>
            </child>
          </object>
        </child>
      </object>
    </child>
</template>

If I remove the titlebar type it will ONLY load the headerbar. Else, it only loads the application and no headerbar. Is there any way to fix this? Thanks!

(Some more info: This app is written in Vala and works fine when I replace Hdy with Gtk in the app window.)

HdyWindow and HdyApplicationWindow don’t have a titlebar child. If you want to have a header bar, pack a HdyHeaderBar inside it like a regular widget.

https://gnome.pages.gitlab.gnome.org/libhandy/doc/master/HdyWindow.html has an example with a header bar in a GtkBox.

The reasoning is - it’s more flexible, while you can just pack it into a box, you can also have structure like:

deck

  • box
    • header bar
    • page
  • box
    • header bar
    • page

etc, which simplifies layouts like that a lot.

Thank you for the answer! Have a good day :slight_smile:

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