First of all, these box layout classes discussed here have no relation with the Layout class. The HorizontalLayout and VerticalLayout classes exist so that you can easily place widgets below or next each other without having to give them exact positions or sizes.

First you create the layout object and give it the size that you want the widgets to fill. Here the widgets will cover the entire width while having a height of 10% of the window.

Let's add some widgets to the currently empty layout.

At this point you have two buttons each taking 50% of the width of the window. Let's put some space between them, but we want the space to be smaller than the actual buttons. Each widget and space have a certain ratio, by default this ratio is 1. To calculate the size of the widget, the ratio is compared with the sum of all ratios. It is easy with an example, we already have two buttons with ratio 1 and we now add a space with ratio 0.5 which brings the total to 2.5. This means that the buttons will each take 40% (1 / 2.5) of the width while the space takes the remaining 20% (0.5 / 2.5). The first parameter to insertSpace is the index which is 1 because we want to insert it between the two buttons.

There are more things that can be said about the box layouts, it is e.g. also possible to give some widgets or spaces and exact size instead of a ratio. But you should check the documentation for a full list of available functions.