Mar-24-2021, 01:47 PM
(This post was last modified: Mar-24-2021, 01:47 PM by deanhystad.)
Use this simple program to get a feel for how the HBox and VBox layout widgets work. Start by commenting out the "setStretch" commands and see how the labels are positioned as you stretch the window. Then uncomment the "content.setStretch" command to pin the "Left" and "Right" labels to the bottom of the screen.
import sys import PySide2.QtWidgets as Qt class MyWindow(Qt.QWidget): def __init__(self): super().__init__() content = Qt.QVBoxLayout(self) content.addWidget(Qt.QLabel('This is the main body')) row = Qt.QHBoxLayout() content.addLayout(row) row.addWidget(Qt.QLabel('Left Side')) row.addWidget(Qt.QLabel('Right Side')) # Up to now the different screen regions all resize proportionally # This makes the row stick to the bottom of the window. It does this # by giving all the vertical "stretch" to the "main body" label content.setStretch(0, 1) # This does the same thing for the horizontal stretch of the bottom row row.setStretch(1, 1) app = Qt.QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec_())If you use QGridLayout you can get the same kind of effect by setting setColumnStretch and setRowStretch.