I am creating a print layout in QGIS. I created a rectangle and I would like to fill it with a line pattern, in such a way that there are exactly five repetitions of the pattern through its height. However, QGIS enables me to choose the spacing, not the number of repetitions, so I would like to use the field calculator to specify height_of_this_rectangle / 4 as spacing.

The problem is that I don't understand how to access the height of the rectangle as a variable in the field calculator expression.

1 Answer 1


You can calculate the height of the rectangle using the following expression:

bounds_height( $geometry)

This will calculate the maximum height of the bounding box of your geometry

enter image description here

  • I cannot use $geometry in print layout mode. It evaluates to NULL, so that bounds_height cannot extract anything useful from it. Does $geometry work for you in print layout mode? Sep 14, 2020 at 15:12
  • Is the rectangle that you are considering to use a geometry contained in a layer or a simple shape created in the layout?
    – Val P
    Sep 14, 2020 at 16:22
  • It is a rectangle shape created in the print layout manager, so the second one that you say. Sep 15, 2020 at 6:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.