title: QTreeView Widget Default Size Takes Up Maximum Amount of Screen Space
body: <p>In the following code, the QTreeView widget always takes up maximum space and leaves minimum space for the QPushButton widget (images after the code). If the QTreeView widget is replaced with an another QPushButton (when code #1 is commented out, and code #2 is commented in), then both buttons get an equal amount of screen space. If QPushButton widgets are replaced with two QTreeView widgets, then space is divided equally between two widgets as well.</p>
  <p>My question is why is QTreeView favoured, regarding screen space, over other widgets like QPushButton and how can I avoid it (how to divide space equally between the two widgets)?</p>
  <p>So far, I have discovered, that the only functions which work are setFixedSize or setFixedWidth, which both are non-preferred solutions.</p>
  <pre><code>import sys
  from PyQt5.QtWidgets import QApplication, QWidget, QMainWindow, QTreeView, QPushButton, QHBoxLayout
  
  
  class TestClass(QMainWindow):
  
      def __init__(self):
          QMainWindow.__init__(self)
  
          self.main_window = QMainWindow()
  
          self.main_widget = QWidget()
          self.main_layout = QHBoxLayout()
  
          self.random_tree = QTreeView()  # &lt;--- Code #1
          self.random_button = QPushButton('Test Button')
          # self.random_button_2 = QPushButton('Test Button')  # &lt;--- Code #2
  
          self.main_layout.addWidget(self.random_tree)  # &lt;--- Code #1
          self.main_layout.addWidget(self.random_button)
          # self.main_layout.addWidget(self.random_button_2)  # &lt;--- Code #2
  
          self.main_widget.setLayout(self.main_layout)
          self.main_window.setCentralWidget(self.main_widget)
  
      def show(self):
          self.main_window.show()
  
  
  if __name__ == &quot;__main__&quot;:
      app = QApplication(sys.argv)
      window = TestClass()
      window.show()
      sys.exit(app.exec_())
  </code></pre>
  <p>Here are the pictures, which describes the situation:</p>
  <p>QTreeView being selfish</p>
  <p><img src="https://i.stack.imgur.com/tqI88.png" alt="" /></p>
  <p>QPushButton widgets sharing the screen in a friendly manner</p>
  <p><img src="https://i.stack.imgur.com/FyzJX.png" alt="" /></p>