Multiple styles are needed together.
1) the background: a solid line with a large width
2) a simple line, with a custom dash pattern. Set the dash length to the length of the inner rectangle, and the space as the space between them. Take note of the total length (referred as
TL below) of a the pattern (dash + space).
3) a marker line, with a simple marker being a vertical line. The markers should be displayed every
4) a second marker line, with a simple marker being a vertical line. The markers should be displayed every
TL with an offset being the length of the dash.
Now you can play with the lines thickness. You may have to adjust the makers placement to cover the dashed line segments (its thickness is like a buffer, in every direction)