Difference XML between GTK3 and GTK4

Hi,

I am currently trying to convert a GTK3 program to GTK4. As Glade is not available for GTK4 and a lot has changed in XML between the two versions, is there a document which explains what is available in GTK4? I know it is recommended to use gtk4-builder-tool, however I find it very buggy and it still doesn’t explain, what parameter are available in GTK4.

Ralf

1 Like

What about https://developer.gnome.org/gtk4/unstable/gtk-migrating-3-to-4.html ?

The “parameters” are always GObject properties.

For custom elements, you should refer to the documentation of each class—for instance GtkWidget. Custom elements are defined by each implementation of the GtkBuildable interface, which means each implementation needs to document them.

Finally, the migration guide contains references and additional information on migrating a UI definition file from GTK3 to GTK4.

Please, file an issue every time you find a bug, making sure to attach the UI definition file that caused the issue.

I get this,

You don’t have permission to access /gtk4/unstable/gtk-migrating-3-to-4.html on this server.

The migrating docs that exist are very good (particularly the porting guide, although I found information lacking particularly in the removal of <packing></packing> for GtkGrid and GtkBox. Eventually I chanced upon some discussion for GtkGrid and found that layout is inserted in the child widget of the grid, rather than after its object (this is a good thing :slight_smile:). In the gjs docs there is reference to GtkGridLayout but not how it’s related to its use in xml,

<!-- n-columns=3 n-rows=3 -->
<object class="GtkGrid" id="scale_grid">
  <property name="visible">True</property>
  <property name="can-focus">True</property>
  <child>
    <object class="GtkLabel">
      <property name="visible">True</property>
      <property name="can-focus">False</property>
      <property name="halign">start</property>
      <property name="margin-top">5</property>
      <property name="margin-start">5</property>
      <property name="label" translatable="yes" context="label-hour">Hours</property>
      <layout>
        <property name="row">0</property>
        <property name="column">1</property>
      </layout>
    </object>
    <!--<packing>
      <property name="left-attach">1</property>
      <property name="top-attach">0</property>
    </packing>-->
  </child>

The other parameter whose documentation is lacking related to <packing> is the position parameter related to GtkBox. it seems in gtk4 there is no way to specify the row or column for a box child (depending on its orientation) you just have to manually reorder the children inside the box.

What would be awesome after delving into this (and coming from the relative naive obscurity of glade :slight_smile:) is a gnome builder plugin to more easily edit xml (collapsible elements, auto-completion and insertion of things like <object class='' id=''></property> and <property name=''></property>. Auto selection of available object class values (GtkLabel, GtkGrid, GtkBox, GtkImage, …) and property names for those class objects is another thing that could really speed up manual editing of xml without being aware of the niceties of its syntax, or the available object properties. and beautifying with tabs/spaces/etc.

Just a bit of a dump there this morning, sorry if I got carried away.

Correct. The position in the UI file determines the position in the box.

If you’re rearranging the children of a GtkBox, you should likely not be using a UI file, though.

Those are not the GJS docs: they are the porting guide for extensions. You should probably file a bug about adding a note to the porting guide.

The GJS documentation is generated from the C API reference, but it seems it’s still using GTK 4.0 when 4.2 is out. You can see an example of the layout properties in the latest documentation for GtkGrid.

1 Like

Yes, that’s a known issue with the developer.gnome.org website. That’s why I recommend using docs.gtk.org for the GTK4 documentation, while we’re fixing developer.gnome.org.

1 Like

Glade allows one to reorder GtkBox children using packing/position. Gtk4 does not have a layout equivalent, that was my only point.

not sure what you mean by “If you’re rearranging the children of a GtkBox, you should likely not be using a UI file, though.” What should one by using in this instance?

I meant manually building the Box widget in your code; you can still define each child widget in the UI definition file, but the Box widget and its contents are defined in code, instead of using XML.

ah, well my gnome shell prefs had 4 stack pages with multiple boxes/grids. Definitely something I wanted to avoid

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