Introduction to Layouts

Below is the initial design for our crop simulation interface, you can see that it is comprised of two main 'windows':

  • One to select the crop type
  • One to control the growth of the crop and to visualise its internal state

Crop simulation GUI showing flow of control

Initially it may seem like we should create two windows - one for each set of functionality. However, PyQt provides us with a method of having only one main window and then being able to switch between different layouts. As well as enabling as to have a single application window, layouts have another benefit: they manage the widgets that are placed inside them. For example, they ensure that your widgets are scaled appropriately to the current window size.

You should always use layouts when developing applications in PyQt and there are three types of layout that we will need to consider:

  1. Horizontal layouts (QHBoxLayout)
  2. Vertical layouts (QVBoxLayout)
  3. Grid layouts (QGridLayout)

Crop selection layout

The design below represent the initial crop selection window. We can simplify this design to show the layout required.

Main window design

Layout representation

As you can see a vertical layout would be appropriate. This would give three rows:

  1. Title
  2. Radio buttons
  3. Submit button

In order to create this layout we must first consider how to put together radio buttons to that they can be considered part of the same group.