pyside6 не выравниваются компоненты в layout

Что я делаю:

  1. Создаю макет формы в QT Designer.
  2. Преобразую его в код python с помощью pyuic6
  3. Подключаю модуль со своей формой.

Что я получаю: вроде рабочее приложение, но размеры и позиции компонентов в layout-ах не меняются при изменении формы.

Что должно быть: при изменении размеров окна должны менятся размеры и позиции компонентов.

Приношу извинения, но не могу правильно вставить код - может плохо старался, но его часть все равно съезжает.

Исходный код:

main.py

import sys
from PySide6.QtWidgets import QApplication, QMainWindow

from main_window_form import Ui_main_window_class


class main_form_class(QMainWindow):

    def __init__(self):
        super(main_form_class, self).__init__()
        self.main_window_form = Ui_main_window_class()
        self.main_window_form.setupUi(self)
        self.main_window_form.pushButton_1.clicked.connect(self.push_button_1_clicked)
        self.main_window_form.pushButton_2.clicked.connect(self.push_button_2_clicked)
        self.main_window_form.pushButton_3.clicked.connect(self.push_button_3_clicked)
        self.main_window_form.pushButton_4.clicked.connect(self.push_button_4_clicked)


    def push_button_1_clicked(self):
        self.main_window_form.label.setText(self.main_window_form.lineEdit.text())

    def push_button_2_clicked(self):
        self.main_window_form.label_2.setText(self.main_window_form.lineEdit.text())

    def push_button_3_clicked(self):
        self.main_window_form.label_3.setText(self.main_window_form.lineEdit.text())

    def push_button_4_clicked(self):
        self.main_window_form.label_4.setText(self.main_window_form.lineEdit.text())

if __name__ == "__main__":
    app = QApplication()
    Main_Window = main_form_class()
    Main_Window.show()
    sys.exit(app.exec())

main_window_form.py:

from PySide6.QtCore import (QCoreApplication, QDate, QDateTime, QLocale,
    QMetaObject, QObject, QPoint, QRect,
    QSize, QTime, QUrl, Qt)
from PySide6.QtGui import (QBrush, QColor, QConicalGradient, QCursor,
    QFont, QFontDatabase, QGradient, QIcon,
    QImage, QKeySequence, QLinearGradient, QPainter,
    QPalette, QPixmap, QRadialGradient, QTransform)
from PySide6.QtWidgets import (QApplication, QHBoxLayout, QLabel, QLineEdit,
    QMainWindow, QPushButton, QSizePolicy, QVBoxLayout,
    QWidget)

class Ui_main_window_class(object):
    def setupUi(self, main_window_class):
        if not main_window_class.objectName():
            main_window_class.setObjectName(u"main_window_class")
        main_window_class.setEnabled(True)
        main_window_class.resize(630, 743)
        sizePolicy = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Expanding)
        sizePolicy.setHorizontalStretch(0)
        sizePolicy.setVerticalStretch(0)
        sizePolicy.setHeightForWidth(main_window_class.sizePolicy().hasHeightForWidth())
        main_window_class.setSizePolicy(sizePolicy)
        self.centralwidget = QWidget(main_window_class)
        self.centralwidget.setObjectName(u"centralwidget")
        self.widget = QWidget(self.centralwidget)
        self.widget.setObjectName(u"widget")
        self.widget.setGeometry(QRect(10, 10, 611, 401))
        self.verticalLayout_5 = QVBoxLayout(self.widget)
        self.verticalLayout_5.setSpacing(10)
        self.verticalLayout_5.setObjectName(u"verticalLayout_5")
        self.verticalLayout_5.setContentsMargins(10, 10, 10, 10)
        self.lineEdit = QLineEdit(self.widget)
        self.lineEdit.setObjectName(u"lineEdit")

        self.verticalLayout_5.addWidget(self.lineEdit)

        self.label_5 = QLabel(self.widget)
        self.label_5.setObjectName(u"label_5")
        sizePolicy1 = QSizePolicy(QSizePolicy.Expanding, QSizePolicy.Fixed)
        sizePolicy1.setHorizontalStretch(0)
        sizePolicy1.setVerticalStretch(0)
        sizePolicy1.setHeightForWidth(self.label_5.sizePolicy().hasHeightForWidth())
        self.label_5.setSizePolicy(sizePolicy1)
        self.label_5.setAlignment(Qt.AlignCenter)

        self.verticalLayout_5.addWidget(self.label_5)

        self.horizontalLayout = QHBoxLayout()
        self.horizontalLayout.setSpacing(10)
        self.horizontalLayout.setObjectName(u"horizontalLayout")
        self.horizontalLayout.setContentsMargins(10, 10, 10, 10)
        self.verticalLayout = QVBoxLayout()
        self.verticalLayout.setObjectName(u"verticalLayout")
        self.pushButton_1 = QPushButton(self.widget)
        self.pushButton_1.setObjectName(u"pushButton_1")
        sizePolicy2 = QSizePolicy(QSizePolicy.Preferred, QSizePolicy.Fixed)
        sizePolicy2.setHorizontalStretch(0)
        sizePolicy2.setVerticalStretch(0)
        sizePolicy2.setHeightForWidth(self.pushButton_1.sizePolicy().hasHeightForWidth())
        self.pushButton_1.setSizePolicy(sizePolicy2)
        self.pushButton_1.setBaseSize(QSize(0, 32))

        self.verticalLayout.addWidget(self.pushButton_1)

        self.label = QLabel(self.widget)
        self.label.setObjectName(u"label")
        sizePolicy2.setHeightForWidth(self.label.sizePolicy().hasHeightForWidth())
        self.label.setSizePolicy(sizePolicy2)
        self.label.setAlignment(Qt.AlignCenter)
        self.label.setWordWrap(False)

        self.verticalLayout.addWidget(self.label)


        self.horizontalLayout.addLayout(self.verticalLayout)

        self.verticalLayout_2 = QVBoxLayout()
        self.verticalLayout_2.setObjectName(u"verticalLayout_2")
        self.pushButton_2 = QPushButton(self.widget)
        self.pushButton_2.setObjectName(u"pushButton_2")
        sizePolicy2.setHeightForWidth(self.pushButton_2.sizePolicy().hasHeightForWidth())
        self.pushButton_2.setSizePolicy(sizePolicy2)

        self.verticalLayout_2.addWidget(self.pushButton_2)

        self.label_2 = QLabel(self.widget)
        self.label_2.setObjectName(u"label_2")
        sizePolicy2.setHeightForWidth(self.label_2.sizePolicy().hasHeightForWidth())
        self.label_2.setSizePolicy(sizePolicy2)
        self.label_2.setAlignment(Qt.AlignCenter)

        self.verticalLayout_2.addWidget(self.label_2)


        self.horizontalLayout.addLayout(self.verticalLayout_2)


        self.verticalLayout_5.addLayout(self.horizontalLayout)

        self.horizontalLayout_2 = QHBoxLayout()
        self.horizontalLayout_2.setSpacing(10)
        self.horizontalLayout_2.setObjectName(u"horizontalLayout_2")
        self.horizontalLayout_2.setContentsMargins(10, 10, 10, 10)
        self.verticalLayout_3 = QVBoxLayout()
        self.verticalLayout_3.setObjectName(u"verticalLayout_3")
        self.pushButton_3 = QPushButton(self.widget)
        self.pushButton_3.setObjectName(u"pushButton_3")
        sizePolicy2.setHeightForWidth(self.pushButton_3.sizePolicy().hasHeightForWidth())
        self.pushButton_3.setSizePolicy(sizePolicy2)

        self.verticalLayout_3.addWidget(self.pushButton_3)

        self.label_3 = QLabel(self.widget)
        self.label_3.setObjectName(u"label_3")
        self.label_3.setEnabled(True)
        sizePolicy2.setHeightForWidth(self.label_3.sizePolicy().hasHeightForWidth())
        self.label_3.setSizePolicy(sizePolicy2)
        self.label_3.setAlignment(Qt.AlignCenter)

        self.verticalLayout_3.addWidget(self.label_3)


        self.horizontalLayout_2.addLayout(self.verticalLayout_3)

        self.verticalLayout_4 = QVBoxLayout()
        self.verticalLayout_4.setObjectName(u"verticalLayout_4")
        self.pushButton_4 = QPushButton(self.widget)
        self.pushButton_4.setObjectName(u"pushButton_4")
        sizePolicy2.setHeightForWidth(self.pushButton_4.sizePolicy().hasHeightForWidth())
        self.pushButton_4.setSizePolicy(sizePolicy2)

        self.verticalLayout_4.addWidget(self.pushButton_4)

        self.label_4 = QLabel(self.widget)
        self.label_4.setObjectName(u"label_4")
        sizePolicy2.setHeightForWidth(self.label_4.sizePolicy().hasHeightForWidth())
        self.label_4.setSizePolicy(sizePolicy2)
        self.label_4.setAlignment(Qt.AlignCenter)

        self.verticalLayout_4.addWidget(self.label_4)


        self.horizontalLayout_2.addLayout(self.verticalLayout_4)


        self.verticalLayout_5.addLayout(self.horizontalLayout_2)

        main_window_class.setCentralWidget(self.centralwidget)

        self.retranslateUi(main_window_class)
        self.lineEdit.textChanged.connect(self.label.update)

        QMetaObject.connectSlotsByName(main_window_class)
    # setupUi

    def retranslateUi(self, main_window_class):
        main_window_class.setWindowTitle(QCoreApplication.translate("main_window_class", u"main_window_class", None))
        self.label_5.setText(QCoreApplication.translate("main_window_class", u"TextLabel", None))
        self.pushButton_1.setText(QCoreApplication.translate("main_window_class", u"PushButton1", None))
        self.label.setText(QCoreApplication.translate("main_window_class", u"TextLabel", None))
        self.pushButton_2.setText(QCoreApplication.translate("main_window_class", u"PushButton2", None))
        self.label_2.setText(QCoreApplication.translate("main_window_class", u"TextLabel", None))
        self.pushButton_3.setText(QCoreApplication.translate("main_window_class", u"PushButton3", None))
        self.label_3.setText(QCoreApplication.translate("main_window_class", u"TextLabel", None))
        self.pushButton_4.setText(QCoreApplication.translate("main_window_class", u"PushButton4", None))
        self.label_4.setText(QCoreApplication.translate("main_window_class", u"TextLabel", None))
    # retranslateUi
  1. xml формы.

     <?xml version="1.0" encoding="UTF-8"?>
     <ui version="4.0">
      <class>main_window_class</class>
      <widget class="QMainWindow" name="main_window_class">
       <property name="enabled">
        <bool>true</bool>
       </property>
       <property name="geometry">
        <rect>
         <x>0</x>
         <y>0</y>
         <width>663</width>
         <height>581</height>
        </rect>
       </property>
       <property name="sizePolicy">
        <sizepolicy hsizetype="Expanding" vsizetype="Expanding">
         <horstretch>0</horstretch>
         <verstretch>0</verstretch>
        </sizepolicy>
       </property>
       <property name="windowTitle">
        <string>main_window_class</string>
       </property>
       <widget class="QWidget" name="centralwidget">
        <widget class="QWidget" name="">
         <property name="geometry">
          <rect>
           <x>20</x>
           <y>20</y>
           <width>611</width>
           <height>531</height>
          </rect>
         </property>
         <layout class="QVBoxLayout" name="verticalLayout">
          <property name="spacing">
           <number>10</number>
          </property>
          <property name="leftMargin">
           <number>10</number>
          </property>
          <property name="topMargin">
           <number>10</number>
          </property>
          <property name="rightMargin">
           <number>10</number>
          </property>
          <property name="bottomMargin">
           <number>10</number>
          </property>
          <item>
           <widget class="QLineEdit" name="lineEdit"/>
          </item>
          <item>
           <layout class="QHBoxLayout" name="horizontalLayout">
            <property name="spacing">
             <number>10</number>
            </property>
            <property name="leftMargin">
             <number>10</number>
            </property>
            <property name="topMargin">
             <number>10</number>
            </property>
            <property name="rightMargin">
             <number>10</number>
            </property>
            <property name="bottomMargin">
             <number>10</number>
            </property>
            <item>
             <layout class="QVBoxLayout" name="verticalLayout_2" stretch="0,0">
              <item>
               <widget class="QPushButton" name="pushButton_1">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="baseSize">
                 <size>
                  <width>0</width>
                  <height>32</height>
                 </size>
                </property>
                <property name="text">
                 <string>PushButton1</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QLabel" name="label">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="text">
                 <string>TextLabel 1</string>
                </property>
                <property name="alignment">
                 <set>Qt::AlignCenter</set>
                </property>
                <property name="wordWrap">
                 <bool>false</bool>
                </property>
               </widget>
              </item>
             </layout>
            </item>
            <item>
             <layout class="QVBoxLayout" name="verticalLayout_6">
              <item>
               <widget class="QPushButton" name="pushButton_2">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="text">
                 <string>PushButton2</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QLabel" name="label_2">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="text">
                 <string>TextLabel 2</string>
                </property>
                <property name="alignment">
                 <set>Qt::AlignCenter</set>
                </property>
               </widget>
              </item>
             </layout>
            </item>
           </layout>
          </item>
          <item>
           <layout class="QHBoxLayout" name="horizontalLayout_2">
            <property name="spacing">
             <number>10</number>
            </property>
            <property name="leftMargin">
             <number>10</number>
            </property>
            <property name="topMargin">
             <number>10</number>
            </property>
            <property name="rightMargin">
             <number>10</number>
            </property>
            <property name="bottomMargin">
             <number>10</number>
            </property>
            <item>
             <layout class="QVBoxLayout" name="verticalLayout_3" stretch="0,0">
              <item>
               <widget class="QPushButton" name="pushButton_3">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="text">
                 <string>PushButton3</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QLabel" name="label_3">
                <property name="enabled">
                 <bool>true</bool>
                </property>
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="text">
                 <string>TextLabel 3</string>
                </property>
                <property name="alignment">
                 <set>Qt::AlignCenter</set>
                </property>
               </widget>
              </item>
             </layout>
            </item>
            <item>
             <layout class="QVBoxLayout" name="verticalLayout_4">
              <item>
               <widget class="QPushButton" name="pushButton_4">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" vsizetype="Fixed">
                  <horstretch>0</horstretch>
                  <verstretch>0</verstretch>
                 </sizepolicy>
                </property>
                <property name="text">
                 <string>PushButton4</string>
                </property>
               </widget>
              </item>
              <item>
               <widget class="QLabel" name="label_4">
                <property name="sizePolicy">
                 <sizepolicy hsizetype="Preferred" 
    

    vsizetype="Fixed"> 0 0 TextLabel 4 Qt::AlignCenter

Исходники: https://drive.google.com/file/d/15wS4NieJ-KaYzrokZdodEmr1yPGWDVBY/view?usp=sharing


Ответы (1 шт):

Автор решения: gil9red
  1. Кликните по свободной области

  2. Кликните на кнопку компоновки

    введите сюда описание изображения

  3. Теперь виджеты и компоновщики адаптируются по размеру: введите сюда описание изображения

→ Ссылка