title: Pyqt5: How to set the size of layout in QStackedLayout or QStackedWidget
body: <p>I am pretty new to pyqt5.</p>
  <p>I have a question regarding qstacklayout. It might be the same question as the <a href="https://stackoverflow.com/questions/28581274/how-to-make-different-pages-of-a-qstackedwidget-of-different-sizes">How to make different pages of a QStackedWidget of different sizes?</a>
  Let's assume that I have done this as below</p>
  <pre><code>class MainUI(QDialog)
      def __init__(self, parent=None):
         super().__init__(parent)
         self.initUI()
      
      def initUI(self):
         self.scroll_area=QScrollArea()
         self.main_layout=QHBoxLayout()
         self.scroll_area.setWidgetResizable(True)
         self.scrollAreaWidgetContents = QWidget()
         self.scrollAreaWidgetContents.setGeometry(QRect(0, 0, 500, 300))
         self.grid_layout = QGridLayout()
         self.grid_layout.addWidget(self.a_widget_ui(), 0, 0)
         ... # Set other widget to grid_layout in position of (1, 0), (2, 0), (3, 0)
          
         self.button_box = QDialogButtonBox(QDialogButtonBox.Ok | QDialogButtonBox.Cancel)
         self.button_box.accepted.connect(self.accept)
         self.button_box.rejected.connect(self.reject)
         
         #set the buttonbox at the end of gridlayout
         self.grid_layout.addWidget(self.button_box, 4, 0)
         self.setLayout(self.main_layout)
         self.setGeometry(300, 300, 790, 800)
      
      def self.a_widget_ui(self):
         group_box = QGroupBox('A Information')
         
         a_list = ['1', '2', '3']
         self.combo_box = QComboBox()
         self.combo_box.addItems(a_list)
         self.combo_box.activated[str].connect(self.update_widget)
         
         self.stacked_layout = QStackedLayout()
         self.A_layout = A_Layout()
         self.B_layout = B_Layout()
         
         self.stacked_layout.addWidget(self.A_Layout)
         self.stacked_layout.addWidget(self.B_Layout)
         
         hbox = QHBoxLayout()
         hbox.addWidget(self.combo_box)
         vbox = QVBoxLayout()
         vbox.addLayout(hbox)
         vbox.addLayout(self.stacked_layout)
         group_box.setLayout(vbox)
         return groupbox
      
      def update_widget(self, choice):
         if choice == &quot;A&quot;:
            self.stacked_layout.setCurrentWidget(self.A_Layout)
         else:
            self.stacked_layout.setCurrentWidget(self.B_Layout)
  </code></pre>
  <p>Then I have these different layouts for A_Layout() and B_Layout()</p>
  <pre><code>class A_Layout(QWidget):
      def __init__(self, parent=None)
          super().__init__(parent)
          grid_layout = QGridLayout()
          grid_layout.addWidget(self.set_a_widget(), 0, 0)
          self.setLayout(grid_layout)
      
      def set_a_widget(self):
          main_widget = QWidget()
          self._a_attrib = QLineEdit()
          self._b_attrib = QLineEdit()
  
          form_layout = QFormedLayout()
          form_layout.addWidget('set a attrib', self._a_attrib)
          form_layout.addWidget('set b attrib', self._b_attrib)
          main_widget.setLayout(form_layout)
          return main_widget
  
  class B_Layout(QWidget):
      def __init__(self, parent=None)
          super().__init__(parent)
          grid_layout = QGridLayout()
          grid_layout.addWidget(self.set_a_widget(), 0, 0)
          self.setLayout(grid_layout)
      
      def set_a_widget(self):
          main_widget = QWidget()
          self._a_attrib = QLineEdit()
          self._b_attrib = QLineEdit()
          self._c_attrib = QLineEdit()
          self._d_attrib = QLineEdit()
  
          form_layout = QFormedLayout()
          form_layout.addWidget('set a attrib', self._a_attrib)
          form_layout.addWidget('set b attrib', self._b_attrib)
          form_layout.addWidget('set c attrib', self._c_attrib)
          form_layout.addWidget('set d attrib', self._d_attrib)
          main_widget.setLayout(form_layout)
          return main_widget
  </code></pre>
  <p>There are some conditions that I've made when I was making this structure.</p>
  <ol>
  <li>I made <code>class A_Layout</code> and <code>class B_Layout</code> in order for me to reuse those Dialog later if needed.</li>
  <li>I used QStackedLayout / QStackedWidget in order for me to update the layout/widget via combobox.</li>
  </ol>
  <p>My questions are the following.</p>
  <ol>
  <li>Is it possible for me to change the layout size dynamically? For example, as you can tell that the size of layout will be different between <code>A_Layout</code> and <code>B_Layout</code> due to the number of components.</li>
  <li>Since I am pretty new, but I have a hunch that I am doing it completely wrong about using qstackedwidget, maybe I should customize the layout such that it would work as qstackedlayout but has more size management</li>
  </ol>
  <p>I would sincerely want to get advice or suggestions if it's possible. What I have tried is to put QSizePolicy before adding layout/widget in stackedlayout and put them whenever I call <code>update_widget</code>. Any other tip or advice would be very appreciated.</p>