import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): # creating the layout and adding the buttons vbox = QVBoxLayout() vbox.addWidget(QPushButton('Button 1')) vbox.addStretch(1) vbox.addWidget(QPushButton('Button 2')) self.setLayout(vbox) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Stretchable Space') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): # creating the layout and adding the buttons with stretchable spaces vbox = QVBoxLayout() vbox.addWidget(QPushButton('Button 1')) vbox.addStretch(1) vbox.addWidget(QPushButton('Button 2')) vbox.addStretch(1) vbox.addWidget(QPushButton('Button 3')) self.setLayout(vbox) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Equal Stretchable Spaces') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())
import sys from PyQt5.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton class Example(QWidget): def __init__(self): super().__init__() self.initUI() def initUI(self): # creating the layout and adding the buttons with a fixed height stretchable space vbox = QVBoxLayout() vbox.addWidget(QPushButton('Button 1')) vbox.addStretch(1) vbox.setSpacing(20) # adding spacing between the buttons and the stretchable space vbox.addStretch(3) vbox.addWidget(QPushButton('Button 2')) self.setLayout(vbox) self.setGeometry(300, 300, 250, 150) self.setWindowTitle('Fixed Height Stretchable Space') self.show() if __name__ == '__main__': app = QApplication(sys.argv) ex = Example() sys.exit(app.exec_())This code is a part of the PyQt5 package library.