title: QMdiArea Leaving the window
body: <p>Is it possible to prevent the windows created in the QMdiArea from going out of the window down or sideways?
  Like the blocking there is to take it out upwards.
  At the moment it is possible to pull out the whole window of the QMdiArea.</p>
  <p>Edit:
  Is it possible to detect window collisions?</p>
  <p>Not necessarily to prevent it from overlapping, but that it is somehow attracted by the other window.</p>
  <pre><code>import sys
  from PyQt5.QtWidgets import *
  from PyQt5 import QtWidgets
  
  class MainWindow(QtWidgets.QMainWindow):
      count = 0
      def __init__(self, parent=None):
          super(MainWindow, self).__init__(parent)
          self.mdi = QMdiArea()
          self.setCentralWidget(self.mdi)
          bar = self.menuBar()
          file = bar.addMenu(&quot;Subwindow&quot;)
          file.addAction(&quot;window1&quot;)
          file.addAction(&quot;text1&quot;)
          file.addAction(&quot;text2&quot;)
          file.triggered[QAction].connect(self.click)
          self.setWindowTitle(&quot;Multiple window using MDI&quot;)
  
      def click(self, q):
          print(&quot;New sub window&quot;)
          if q.text() == &quot;window1&quot;:
              MainWindow.count = MainWindow.count + 1
              sub = QMdiSubWindow()
              sub.setWidget(QTextEdit())
              sub.setWindowTitle(&quot;subwindow&quot; + str(MainWindow.count))
              self.mdi.addSubWindow(sub)
              sub.show()
  
          if q.text() == &quot;text1&quot;:
              self.mdi.cascadeSubWindows()
  
          if q.text() == &quot;text2&quot;:
              self.mdi.tileSubWindows()
  
  def main():
      app = QApplication(sys.argv)
      ex = MainWindow()
      ex.show()
      sys.exit(app.exec_())
  
  if __name__ == '__main__':
      main()
  </code></pre>