Adw.PreferencesWindow as GtkBuildable

The Adw.PreferencesWindow inherits from GtkBuildable but there seems to be no example of how to create it in a .ui file in the documentation. I tried extending it using a template element like in the code below but I keep getting this warning:

Adwaita-WARNING **: 18:51:32.879: Child name 'test_1' not found in AdwViewStack

Here are the .ui contents. I have no idea what to do here.

<?xml version="1.0" encoding="UTF-8"?>
<interface>
  <requires lib="gtk" version="4.10" />
  <requires lib="Adw" version="1.0" />
  <template class="Gjs_MyPreferencesWindow" parent="AdwPreferencesWindow">
    <property name="default_width">500</property>
    <property name="default_height">500</property>
    <property name="modal">true</property>
    <property name="title">Preferences test</property>
    <property name="visible_page_name">test_1</property>
    <property name="destroy_with_parent">true</property>
    <property name="content">
      <object class="GtkBox">
        <property name="orientation">vertical</property>
        <property name="halign">center</property>
        <property name="valign">center</property>
        <child>
          <object class="AdwPreferencesPage" id="test_1">
            <property name="name">test_1</property>
            <property name="title">Test Page 1</property>
          </object>
        </child>
        <child>
          <object class="AdwPreferencesPage">
            <property name="name">test_2</property>
            <property name="title">Test Page 2</property>
          </object>
        </child>
        <child>
          <object class="AdwPreferencesPage">
            <property name="name">test_3</property>
            <property name="title">Test Page 3</property>
          </object>
        </child>
      </object>
    </property>
  </template>
</interface>

The warning mentions AdwViewStack. I wonder where it is coming from.

And I also wonder why it forced me to prepend the Gjs_ characters to the GtypeName so that I have Gjs_MyPreferencesWindow. Without adding the Gjs_ characters to the template class, the template build fails.

You shouldn’t need to use a Gtk.Box as the Adw.PreferencesWindow:content child, and in fact that’s probably becoming the only page in the window, while the Adw.PreferencesPage objects are children of the Gtk.Box instead. Usually you’d want to use Adw.PreferencesWindow:visible-page and the GtkBuilder id also.

The behavior of GType names in GJS is documented here and here.

1 Like

You’re not allowed to use content on pref window. It’s same as always: when you create one of the standard GTK dialogs, you don’t want to set child, right? Same here, just add pages via <child>.

The docs are missing since in GTK3 that was a given for any widgets - <child> does the same thing as gtk_container_add(), and you were using that to add pages to pref window. Now we probably should document that <child> maps to adw_preferences_window_add(), but it’s no different from, say, GtkBox.

2 Likes

Thanks. The GTypeName error was due to a small mistake I made. I was setting it using GtypeName property instead of GTypeName.

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