title: Qt: QPushButton vertical size, fit to contents?
body: <p>Is there any way to reliably have a push button's height fit to its contents? Some previous answers suggest using layouts and size policies, or maximum height (<a href="https://stackoverflow.com/questions/58728873/how-to-make-height-of-a-qpushbutton-automatically-fit-the-text">How to make height of a QPushButton automatically fit the text?</a>, <a href="https://stackoverflow.com/questions/45100018/increase-height-of-qpushbutton-in-pyqt">Increase Height of QPushButton in PyQT</a>, <a href="https://stackoverflow.com/questions/58537802/how-can-i-set-a-qpushbutton-to-grow-vertically">How can I set a QPushButton to grow vertically?</a>), but they don't seem to work for me.</p>
  
  <p>See the example below. The two buttons are drawn with their default "one line" height, so the text inside is clipped. Setting their size policies as <code>Preferred</code> or <code>Minimum</code> doesn't change anything. Using <code>addStretch</code> instead of <code>setAlignment</code> doesn't change anything (using none makes the buttons stretch to fill the window, which is not what I want). Changing the minimum height works, but that's far from practical, unless there's some way to automatically compute and set it.</p>
  
  <pre><code>#!/usr/bin/env python3
  
  import sys
  from PyQt5 import QtCore, QtWidgets
  from PyQt5.QtWidgets import *
  from PyQt5.QtCore import QSize    
  
  
  class HelloWindow(QMainWindow):
      def __init__(self):
          QMainWindow.__init__(self)
  
          button1 = QPushButton()
          l = QVBoxLayout()
          l.addWidget(QLabel('One'))
          l.addWidget(QLabel('Description of button one'))
          button1.setLayout(l)
          #button1.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
          #button1.setMinimumHeight(50)
  
          button2 = QPushButton()
          l = QVBoxLayout()
          l.addWidget(QLabel('Two'))
          l.addWidget(QLabel('Description of button two\nwith extra line'))
          button2.setLayout(l)
          #button2.setSizePolicy(QSizePolicy.Preferred, QSizePolicy.Preferred)
          #button2.setMinimumHeight(65)
  
          layout = QVBoxLayout()
          layout.addWidget(button1)
          layout.addWidget(button2)
          #layout.addStretch(1)
          layout.setAlignment(QtCore.Qt.AlignTop)
  
          centralWidget = QWidget(self)          
          centralWidget.setLayout(layout)
          self.setCentralWidget(centralWidget)   
  
          self.resize(200, 400)
  
  
  if __name__ == "__main__":
      app = QtWidgets.QApplication(sys.argv)
      mainWin = HelloWindow()
      mainWin.show()
      sys.exit( app.exec_() )
  </code></pre>