title: Stop widgets from overlapping each other and add space between them
body: <p>I am using <code>QHBoxLayout</code> for layout. The breakdown is: pic.1 is what happens, pic.2 is what I want - widgets don't overlap and there is a gap between them. For pic.2, I created a <code>Gap</code> widget to stick between the existing widgets. But this is a cumbersome solution which implies extra maintenance (especially when I have more than two widgets to care for). Moreover, since B overlaps A, I think the newly added gap widget overlaps A as well, maybe according the fraction of its size. I am not so sure about this.</p>
  
  <p><a href="https://i.stack.imgur.com/jxBCf.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/jxBCf.png" alt="pic 1"></a></p>
  
  <p><a href="https://i.stack.imgur.com/M2Ne8.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/M2Ne8.png" alt="pic 2"></a></p>
  
  <p>I tried using <code>self.layout.addSpacing(10)</code>, but that doesn't work. The red widget shifts by 10 pixels from where it was before, not from the border of the widget on the left.</p>
  
  <p>Note, too, that the contained widgets will all have some minimum width specification.</p>
  
  <p>So, how can I add the space between two widgets like in pic.2?</p>
  
  <pre><code>import sys
  from PyQt5.QtWidgets import *
  from PyQt5.QtGui import *
  from PyQt5.QtCore import *
  
  class Gap(QWidget):
      def __init__(self, parent=None):
          super().__init__(parent=parent)
          self.setMinimumWidth(10)
          self.setMinimumHeight(1)
  
  class Line(QWidget):
      def __init__(self, parent=None):
          super().__init__(parent=parent)
  
          # Set layout
  
          self.layout = QHBoxLayout()
          self.setLayout(self.layout)
  
          # Set palette
  
          self.palette1 = QPalette()
          self.palette1.setColor(QPalette.Window, Qt.red)
  
          self.palette2 = QPalette()
          self.palette2.setColor(QPalette.Window, Qt.blue)
  
          self.palettebg = QPalette()
          self.palettebg.setColor(QPalette.Window, Qt.green)
          self.setAutoFillBackground(True)
          self.setPalette(self.palettebg)
  
          # Set labels
  
          self.label1 = QLabel(self)
          self.label1.setText("A")
          self.label1.setStyleSheet('font-size: 36pt;')
          self.label1.adjustSize()
          self.label1.setAutoFillBackground(True)
          self.label1.setPalette(self.palette1)
          self.label1.setMinimumSize(36, 36)
  
          self.label2 = QLabel(self)
          self.label2.setText("B")
          self.label2.move(30, 0)
          self.label2.setStyleSheet('font-size: 36pt;')
          self.label2.adjustSize()
          self.label2.setAutoFillBackground(True)
          self.label2.setPalette(self.palette2)
          self.label2.setMinimumSize(36, 36)
  
          self.gap = Gap()
  
          self.layout.addWidget(self.label1)
          # self.layout.addWidget(self.gap)
          # self.layout.addSpacing(10)
          self.layout.addWidget(self.label2)
  
  class App(QMainWindow):
  
      def __init__(self):
          super().__init__()
          self.title = 'PyQt5'
          self.left = 10
          self.top = 10
          self.width = 200
          self.height = 54
          self.initUI()
  
      def initUI(self):
          self.setWindowTitle(self.title)
          self.setGeometry(self.left, self.top, self.width, self.height)
  
          self.line = Line(self)
          self.line.resize(74, 54)
          self.line.move(50, 50)
  
          self.show()
  
  if __name__ == '__main__':
      app = QApplication(sys.argv)
  
      # CUSTOM
      app.setFont(QFontDatabase().font("Monospace", "Regular", 14))
  
      ex = App()
      sys.exit(app.exec_())
  </code></pre>
  
  <p><strong>EDIT</strong> clarification, as requested: (1) suppose the size of the parent widget is too small (and cannot be resized), (2) the parent widget has QHBoxLayout with widgets A and B added to it, (3) the parent widget being too small, QHBoxLayout aranges the child widgets A and B such that they overlap each other like in the first picture. (4) Such overlap is undesirable, instead the widgets just need to be placed one after another, with no overlap, and with gap between them, like in picture 2. I don't know how to do this with QHBoxLayout.</p>
  
  <p><strong>EDIT 2</strong> Here is a visual explanation. </p>
  
  <p>The green here is the parent widget - <strong>not resizable by assumption</strong>. Widget A is added:</p>
  
  <p><a href="https://i.stack.imgur.com/wFZlR.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/wFZlR.png" alt="enter image description here"></a></p>
  
  <p>Add widget B:</p>
  
  <p><a href="https://i.stack.imgur.com/fJwez.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/fJwez.png" alt="enter image description here"></a></p>
  
  <p>Now, widget B is on top of A. I don't want it. I want this instead:</p>
  
  <p><a href="https://i.stack.imgur.com/b1s9e.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/b1s9e.png" alt="enter image description here"></a></p>