from PyQt5 import QtCore, QtWidgets
class TextSubWindow(QtWidgets.QTextEdit):
    """
    TextEdit that saves it size when it closes and closes itself if the main widget disappears.
    """
    def __init__(self):
        super(TextSubWindow, self).__init__()
        self.setWindowFlags(QtCore.Qt.SubWindow)
        self._size = None

    def sizeHint(self, *args):
        """
        Return the saved size.
        """
        if self._size:
            return self._size
        else:
            return super(TextSubWindow, self).size()

    def closeEvent(self, *args):
        """
        Store the size of the window.
        """
        self._size = self.size()
        super(TextSubWindow, self).closeEvent(*args)

from PyQt5 import QtWidgets
class TextSubWindow(QtWidgets.QTextEdit):
    """
    TextEdit that saves it size when it closes and closes itself if the main widget disappears.
    """
    def __init__(self):
        super(TextSubWindow, self).__init__()
        self._size = None

    def sizeHint(self, *args):
        """
        Return the saved size.
        """
        if self._size:
            return self._size
        else:
            return super(TextSubWindow, self).size()

    def closeEvent(self, *args):
        """
        Store the size of the window.
        """
        self._size = self.size()
        super(TextSubWindow, self).closeEvent(*args)

Fix problem with copying from text window.
Fix problem with copying from text window.

closes #9843

- from PyQt5 import QtCore, QtWidgets
+ from PyQt5 import QtWidgets
  class TextSubWindow(QtWidgets.QTextEdit):
      """
      TextEdit that saves it size when it closes and closes itself if the main widget disappears.
      """
      def __init__(self):
          super(TextSubWindow, self).__init__()
-         self.setWindowFlags(QtCore.Qt.SubWindow)
          self._size = None
  
      def sizeHint(self, *args):
          """
          Return the saved size.
          """
          if self._size:
              return self._size
          else:
              return super(TextSubWindow, self).size()
  
      def closeEvent(self, *args):
          """
          Store the size of the window.
          """
          self._size = self.size()
          super(TextSubWindow, self).closeEvent(*args)
  
Fix problem with copying from text window.
## Code Before:
from PyQt5 import QtCore, QtWidgets
class TextSubWindow(QtWidgets.QTextEdit):
    """
    TextEdit that saves it size when it closes and closes itself if the main widget disappears.
    """
    def __init__(self):
        super(TextSubWindow, self).__init__()
        self.setWindowFlags(QtCore.Qt.SubWindow)
        self._size = None

    def sizeHint(self, *args):
        """
        Return the saved size.
        """
        if self._size:
            return self._size
        else:
            return super(TextSubWindow, self).size()

    def closeEvent(self, *args):
        """
        Store the size of the window.
        """
        self._size = self.size()
        super(TextSubWindow, self).closeEvent(*args)

## Instruction:
Fix problem with copying from text window.
## Code After:
from PyQt5 import QtWidgets
class TextSubWindow(QtWidgets.QTextEdit):
    """
    TextEdit that saves it size when it closes and closes itself if the main widget disappears.
    """
    def __init__(self):
        super(TextSubWindow, self).__init__()
        self._size = None

    def sizeHint(self, *args):
        """
        Return the saved size.
        """
        if self._size:
            return self._size
        else:
            return super(TextSubWindow, self).size()

    def closeEvent(self, *args):
        """
        Store the size of the window.
        """
        self._size = self.size()
        super(TextSubWindow, self).closeEvent(*args)
