spacer = QSpacerItem(40, 20, QSizePolicy.Expanding, QSizePolicy.Minimum) layout.addItem(spacer)
spacer = QSpacerItem(20, 40, QSizePolicy.Minimum, QSizePolicy.Expanding) layout.addItem(spacer)This code creates a vertical spacer item of height 40 and width 20, using minimum and expanding policies for size hint and maximum size respectively. It is added to a layout to create vertical space between two widgets. In both examples, we use the QSizePolicy.Expanding policy for size hint to ensure that the space can expand to fill any remaining layout space. These examples demonstrate the use of PyQt5.QtWidgets QSpacerItem to add spacing between widgets in a layout.