Теперь я хотел бы получить этот коэффициент растяжения из SpacerItem, но не могу найти, как это сделать.
Код: Выделить всё
item.sizePolicy().verticalStretch()Код: Выделить всё
from PyQt6.QtWidgets import QApplication, QWidget, QVBoxLayout, QPushButton, QSpacerItem
class Window(QWidget):
def __init__(self):
super().__init__()
self.setGeometry(700, 500, 100, 200)
self.layout = QVBoxLayout(self)
for i in range(3):
but = QPushButton(f'Push {i}')
self.layout.addWidget(but)
if i == 0:
but.clicked.connect(self.click)
self.layout.insertStretch(1, 2)
self.layout.insertStretch(3, 3)
def click(self):
for i in (1, 3):
stretch = self.layout.itemAt(i)
assert isinstance(stretch, QSpacerItem)
pol = stretch.sizePolicy()
print(pol.verticalStretch())
app = QApplication([])
window = Window()
window.show()
app.exec()
Подробнее здесь: https://stackoverflow.com/questions/789 ... paceritems